[Haskell-cafe] n00b question: defining datatype

Daniel Schoepe daniel.schoepe at googlemail.com
Thu Aug 6 06:57:54 EDT 2009


On Thu, Jul 23, 2009 at 08:17:34PM +0100, Iain Barnett wrote:
> [..]
> against the empty list it's not really a problem to have it there. I didn't
> realise I could use Maybe in the constructor because it's a monad, but
> that's good because I was wondering about the best way to make a nullable
> value.

Actually, this has nothing to do with Maybe being a monad. The reason
you can do this is because "Maybe" itself is not a type, but a (unary)
type constructor(It has kind * -> *), so you need to apply it to
another type. Doing something like "test :: Maybe" would be an error.

> That Data.Tree module looks interesting too! It does seem to be a
> naturally recursive type, but I'm still trying to become easy with that sort
> of thought :)
> [..]

A list is also recursively defined, so it is not really more difficult
to use a Tree instead. E.g. one could define a list type like this:
 data List a = Nil | Cons a (List a)

- Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/ac1ad0e5/attachment.bin


More information about the Haskell-Cafe mailing list