[Haskell-beginners] Enum for natural numbers

kane96 at gmx.de kane96 at gmx.de
Fri Dec 18 12:42:45 EST 2009


ahhh, ok, thanks so far. Here is how the output should looks like:
*Main> toEnum (-1) :: Nat
Z
*Main> toEnum 0 :: Nat 
Z
*Main> toEnum 1 :: Nat 
S Z 
*Main> fromEnum (S (S Z)) 
2

the first three things work, but I don't know about the last one. Does anybody how it should work and what's the sense of it?


-------- Original-Nachricht --------
> Datum: Fri, 18 Dec 2009 18:06:32 +0100
> Von: Deniz Dogan <deniz.a.m.dogan at gmail.com>
> An: kane96 at gmx.de
> CC: beginners at haskell.org
> Betreff: Re: [Haskell-beginners] Enum for natural numbers

> 2009/12/17  <kane96 at gmx.de>:
> > Hi,
> > I have data Nat = Z | S Nat deriving (Eq,Ord,Show)
> >
> > 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
> > --
> > GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> 
> Fill in the gaps:
> 
> instance Enum Nat where
>     toEnum x | x <= 0 = ...
>              | otherwise = ...
> 
> -- 
> Deniz Dogan

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser


More information about the Beginners mailing list