[Haskell] nwebie question

Sebastian Sylvan sebastian.sylvan at gmail.com
Sat Oct 1 15:13:07 EDT 2005


On 10/1/05, justebelmont at argentina.com <justebelmont at argentina.com> 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


More information about the Haskell mailing list