On 10/1/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>

>
> Hi there folks, I'm trying to learn some functional programming in
 Haskell,
> well, at the College, but they don't teach anything, lol, so I have a
 very
> simple question about type creation.


>
> This is a new type that contains the int and the new infinity number




>
> data NatInf = Infinity | Num Int




>
> At this point every seems to be ok, but when I load the file in Hugs,
 and
> then write




>
> Num 5 (or Infinity)




>
> the following error appears:








>
> ERROR – Cannot find "show" function for:
> *** Expression : Num 5
> *** Of type:    : NatInf

This means that you have not yet specified how you want your new data
type to be converted to a string (using the function "show" in the
Show type class).

Either you write your own implementation

instance Show NatInf where
  show (Num x) = ...
  show (Infinity) = ...

Or you can simply derive a standard one by typing "deriving Show" at
the end of your data declaration.

data NatInf = Infinity | Num Int deriving Show

/S

 --
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to