[Haskell-cafe] Sillyness in the standard libs.

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Mon Nov 19 17:10:51 EST 2007


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] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH




More information about the Haskell-Cafe mailing list