[Haskell] (no subject)
Chaddaï Fouché
chaddai.fouche at gmail.com
Wed Sep 5 17:30:43 EDT 2007
2007/9/5, Tomi Owens <t.owens at hautlieu.sch.je>:
> So now I try to apply the function to the list:
>
> Prelude> map (f) [(a2+b2,a)| a <- [1..4] , b<- [1..4], a2+b2<20, b<=a]
>
> and I get this result:
>
> <interactive>:1:5:
> Ambiguous type variable `t' in the constraints:
> `Integral t' arising from use of `f' at <interactive>:1:5
> `RealFrac t' arising from use of `f' at <interactive>:1:5
> Probable fix: add a type signature that fixes these type variable(s)
>
>
> I'm sorry, but I don't quite get how to set the type signature and how it
> will apply to my function...
>
It's because f need a real, not an integer as the second element of
its parameter (since it use (/) in (10000/b)), and as it also needs an
integer as it's first, the type checker don't know what the type of a
should be (it can't be both an integer and a floating value at the
same time).
The easiest IMO is to keep a as an integer, but use "fromIntegral" to
convert it to a real in the second part of the tuple :
map f [( a^2+b^2, fromIntegral a) | a <- [1..4] , b<- [1..4], a^2+b^2<20, b<=a]
You would get more help and faster from an IRC channel like
#haskell at irc.freenode.net though.
--
Jedaï
More information about the Haskell
mailing list