Unless I'm missing something in your description, why not
data Container a = Single a | Many a a [a]
Dan
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.
Günther
or
data Container a = Container a [a]
- Jake
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe