generic implementation of Bits.toIntegralSized

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

generic implementation of Bits.toIntegralSized

Henning Thielemann

Documentation of toIntegralSized gives following generic implementation:

toIntegral :: (Integral a, Integral b) => a -> Maybe b
toIntegral x
   | toInteger x == y = Just (fromInteger y)
   | otherwise        = Nothing
   where
     y = toInteger x


I expect that (toInteger x == toInteger x) is always true because of
referential transparency, right? I assume the intent was to compare the
Integer representations of the parameter and the result. Maybe it should
be this way:

toIntegral :: (Integral a, Integral b) => a -> Maybe b
toIntegral x
   | toInteger x == toInteger y  = Just y
   | otherwise                   = Nothing
   where
     y = fromInteger $ toInteger x
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries