[Haskell-beginners] Modeling recursive data structs
Nikolay Artamonov
nartamonov at gmail.com
Fri Nov 5 23:37:42 EDT 2010
Hi all! How can we model in Haskell three hypothetic data structures
A, B, C which obey following conditions:
1. A is anything
2. B is list of A's
3. C is list of A's or B's or another C's
So, for example, it would be possible to write something like: C [A, B
[A, A], A, C [A, B [A]]].
I wrote this code:
data Super = A | B [A] | C[Super]
Not surprisingly, Haskell refused to accept subexpression `B[A]`,
because "Not in scope: type constructor or class `A'". How to solve
this problem?
More "real" example of A, B and C:
data Shape = Point Int Int | Polyline [Point] | Shape [Shape]
Interestingly, if I replace Polyline [Point] to Polyline [Shape] then
definition will be accepted. But what if I want *polylines* consists
of *points*, not any *shapes*?
Thank you!
--
Nikolay Artamonov
More information about the Beginners
mailing list