[Haskell-cafe] showing a user defined type
michael rice
nowgate at yahoo.com
Mon May 18 21:20:58 EDT 2009
I've been playing around with "The Little MLer" (pg. 95, 96) to try to improve my understanding of types.
I can ask ML:
- ints(0);
val it = Link (1,fn) : chain
-
and Haskell:
*Main> :t ints 0
ints 0 :: Chain
*Main> ints 0
<interactive>:1:0:
No instance for (Show Chain)
arising from a use of `print' at <interactive>:1:0-5
Possible fix: add an instance declaration for (Show Chain)
In a stmt of a 'do' expression: print it
*Main>
I think I need to write a show function for type Chain but not
sure how to proceed.
Michael
===============
;;ML
datatype chain =
Link of (int * (int -> chain))
fun ints(n)
= Link(n + 1, ints)
;;Haskell
data Chain = Link Int (Int -> Chain)
ints :: Int -> Chain
ints n = Link (n+1) ints
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090518/b3a2d01d/attachment.html
More information about the Haskell-Cafe
mailing list