On Nov 19, 2007, at 16:50 , Henning Thielemann wrote:

On Mon, 19 Nov 2007, Brandon S. Allbery KF8NH wrote:
fromEnum and/or toEnum are helpful for this kind of thing, and I am
occasionally tempted to bind "cast = toEnum . fromEnum" because I
need it so much.

Really? I'd like to know which examples these are. So far I suspected that
'cast' indicates not well chosen types.


If so, it's not my types... The specific instance is the one you mentioned about times; fromEnum lets me turn a Foreign.C.Types.CTime (== System.Posix.Types.EpochTime) to an Int (which is commonly just type punning in GHC, since it's the same internal value representation in most (all?) cases), from which I can get to another Foreign.C.Types type with toEnum or to Integer with fromIntegral. (NB: This involves an assumption about CTime; POSIX allows (or used to allow) it to be a floating type in order to allow some non- UNIXlikes to represent POSIX times. But given that CTime is Enum, Foreign.C.Types already violates this; so why isn't it also Integral?)

So yes, this is a sign of typing issues in the implementation and (toEnum . fromEnum) is a hack around them.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to