[Haskell-cafe] Re: Non Empty List?

Ketil Malde ketil at malde.org
Fri Jun 5 18:10:50 EDT 2009

MH <mhamro at gmail.com> writes:

> data Container a = Many a(Container a)

> but here is what I don't understand (fyi, I am a beginner) how can you
> construct  this container? I can do

> let a = Many "somestring" - and I will get back a function but I can not do
> let a = Many 'a' "somestring"  - because the second param is not
> (Container a) type.

Right, so you need to pass a 'Container a' for that parameter.

> let a = Many 'a' (Container ['a','a']) - doesn't work either because
> Container is a type not a constructor (right or I am missing
> something?).

It doesn't work because the Container parameter must be of the same
type.  The parameters here are Char (due to the 'a' as the first
parameter to Many), and [Char] (due to the ['a','a'] given as
parameter to the Container parameter.  These are not the same, so it

> So I have two questions:
> 1. When I do
> let b = Many "somestring" , I get
> :t b
> b :: Container[Char] -> Container[Char]
> what is it and why I am allowed to pass just one parameter to Many
> (and how can I use it)?

This is just partial application.  Pass one more parameter to build
the whole thing.

> 2. How can you construct that container?
> data Container a = Many a(Container a)
> let a = ????

Well you need a 'Container a' to do it.  So you can do for instance:

  let a = Container 'x' a


  let b = Conainer 'y' undefined

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list