
Of course your safeFromInteger isn't really safe, what about the minBound?
=)
On Tue, Apr 7, 2009 at 5:27 PM, Kannan Goundan
Here's my code (in file "Test.hs")
safeFromInteger :: (Num a, Integral a, Bounded a) => Integer -> Maybe a safeFromInteger i = if i > (toInteger maxBound) then Nothing else Just (fromInteger i)
Here's the error from GHCi 6.10.1:
Test.hs:3:19: Ambiguous type variable `a' in the constraints: `Bounded a' arising from a use of `maxBound' at Test.hs:3:19-26 `Integral a' arising from a use of `toInteger' at Test.hs:3:9-26 Probable fix: add a type signature that fixes these type variable(s)
It's almost like GHC thinks that the type variable "a" can't be part of the "Bounded" lass and the "Integeral" class.
I plan to use "safeFromInteger" for converting from Word8, Word16, Word32, etc.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe