[Haskell-beginners] Enum for natural numbers

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Thu Dec 17 13:56:30 EST 2009

On Dec 17, 2009, at 12:21 , kane96 at gmx.de wrote:
> toEnum should return Z for negative numbers. I did something like  
> this but the problem is I don't know how to set "less than". I tried  
> > and lt:
> instance Enum Nat where
>    toEnum (gt 0) = S Z
>    toEnum (lt 1) = Z

Take a look at guards.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20091217/edb90242/PGP.bin

More information about the Beginners mailing list