[Haskell-cafe] Non Empty List?

Tom Lokhorst tom at lokhorst.eu
Thu Jun 4 19:21:55 EDT 2009


Are you looking for something like Streams [1]?

They're infinite sequences, defined like this:

data Stream a = Cons a (Stream a)

They can obviously never be empty (unless you see bottom (undefined) as empty).

- Tom

[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Stream

On Thu, Jun 4, 2009 at 11:53 PM, GüŸnther Schmidt <gue.schmidt at web.de> wrote:
> Hi,
>
> I need to design a container data structure that by design cannot be empty
> and can hold n elements. Something like a non-empty list.
>
>
> I started with:
>
> data Container a = Single a | Many a [a]
>
> but the problem above is that the data structure would allow to construct a
> Many 5 [] :: Container Int.
>
> I can't figure out how to get this right. :(
>
> Please help.
>
> Günther
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list