Given a set of A, B, C, D... where A contains an ordered list of As, Bs, Cs, ... and Bs have a list of Bs, Cs, Ds... and so on such that any given element can't contain any instances of a 'higher' type how would you model this?
data Hier a = A [a] | B [a] | C [a] | D [a]
allows this nesting but won't prevent putting a A into a B.
data A = A [ACont]
data B = B [BCont]
data C = C [CCont]
data D = D
data ACont = AA A | AB B | AC C | AD D
data BCont = BB B | BC C | BD D
data CCont = CC C | CD D
pattern PatAA x <- AA (A x) where
PatAA x = AA (A x)
get the nesting right but... yuck. Seven types, a zoo of constructors, no obvious functor instance, and then generically traversing this structure won't be fun. You can reduce the pain a little with some pattern synonyms (one show), but not a heck of a lot.
Is this the best that can be done?