[Haskell-cafe] Trying to write 'safeFromInteger'
Henning Thielemann
lemming at henning-thielemann.de
Fri Apr 10 18:54:12 EDT 2009
On Wed, 8 Apr 2009, Neil Mitchell wrote:
> That seems a really weird way to write it! Who decided all auxiliary
> functions should be called go? (I think I'm blaming dons) - why not:
>
> sffi :: (Integral a,Num a) => Integer -> Maybe a
> sffi n | toInteger n2 == n = Just n2
> | otherwise = Nothing
> where n2 = fromInteger n
I think it is a bug, that 'fromInteger' is defined for numbers outside the
range of the target type. Why is it necessary to have, say
fromInteger 1000 == (232 :: Word8)
?
I would not rely on this behaviour and safeFromInteger should also work,
when the fromInteger method yields undefined for some Integer input.
More information about the Haskell-Cafe
mailing list