[Haskell-cafe] Re: Non Empty List?
westondan at imageworks.com
Thu Jun 4 19:45:50 EDT 2009
Unless I'm missing something in your description, why not
data Container a = Single a | Many a a [a]
Günther Schmidt wrote:
> 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.
>> data Container a = Container a [a]
>> - Jake
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe