[Haskell-cafe] Re: Non Empty List?
Günther Schmidt
gue.schmidt at web.de
Thu Jun 4 19:39:12 EDT 2009
Hi Jake,
Jake McArthur schrieb:
> Günther Schmidt wrote:
>> 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 think you meant to do either
>
> data Container a = Single a | Many a (Container a)
nope, I pretty much meant what I wrote above, the solution here would
mean deeply nested containers, since it's a recursive data structure.
I need a data structure as in my example without the [] being possible
to be empty.
It's quite possible that in order to achieve this I would need to split
this in 2 separate data declarations.
The idea behind this is that an "a" can "pocket" siblings, but only one
level deep and that an "a's" list of "pocketed/swallowed" siblings must
not be empty, because otherwise it would automatically be an "Single a".
Sorry, I really don't know how to put this better.
Günther
>
> or
>
> data Container a = Container a [a]
>
> - Jake
More information about the Haskell-Cafe
mailing list