
19 Oct
2007
19 Oct
'07
6:54 a.m.
To convert to and from integrals you could define two functions: binToNum :: Num a => Bin -> a binToNum Zero = 0 binToNum One = 1 numToBin :: Num a => a -> Bin numToBin 0 = Zero numToBin _ = One Or you could derive Enum for your Bin type. This wil automatically associate integers with the constructors of your type, in the order given. (See section 10.2 of the haskell report: http://www.haskell.org/onlinereport/derived.html) data Bin = Zero | One deriving Enum fromEnum Zero
0 fromEnum One 1
If this is not what you want, could you specify more precisely what difficulty you ran into?