It looks like somewhere else in your program (or a type signature
somewhere) is trying to force the result of sqrt to be an Int which
won't work since square roots are irrational (represented by the
computer as a Float or Double).

You might try (1) making sure the place where distBetween is used
isn't trying to use only Ints or Integers and (2) taking off explicit
type signatures and seeing if that works (the compiler can usually get
things working for you as long as you don't give it misinformation in
type signatures). Also, a more useful type of Point if you are taking
distances would be

type Point = (Float,Float)

instead (or you can leave that out because the function type for
distBetween will be inferred to be the "right thing", i.e.
(Float,Float) is already a valid type without needing to be named).

Hope that helps,
  Jared.
--
http://www.updike.org/~jared/
reverse ")-:"

On 4/27/06, Aditya Siram <[EMAIL PROTECTED]> wrote:
> Hi all,
> I just started working with Haskell and am having some difficulties with its
> type system.
> Here is function that is supposed to calculate the distance between two
> coordinates:
> distBetween (x1,y1) (x2,y2) = sqrt((x2-x1)^2  + (y2-y1)^2)
>
> I am trying to explictly give it a type signature. Here is what I have tried
> and the errors generated by Hugs:
>
> type Point = (Int,Int)
> distBetween :: Point -> Point -> Float
> >>ERROR - Type error in explicitly typed binding
> *** Term           : distBetween
> *** Type           : Point -> Point -> Int
> *** Does not match : Point -> Point -> Float
>
> distBetween :: Point -> Point -> Int
> >>Instance of Floating Int required for definition of distBetween
>
> Any help is appreciated...
> Deech
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to