Skip to content

Instantly share code, notes, and snippets.

@blt

blt/Q.lhs

Created Aug 14, 2015
Embed
What would you like to do?
> module Q where
I have a situtation where it would be extremely useful to limit
the self-recursion of a data type to only a subset of its
constructors. Consider the datatype T below:
> data T
> = A integer
> | B T float
> | C T [float]
> | OnlyBs T [T] -- list should be only of B's
> | OnlyCs T [T] -- list should be only of C's
In the last two constructors I would prefer that the final list
be limited to being composed only of B's and C's, as per the
comment. I could provide explicit constructors that deny any
other construction but I wonder if there's a way to express
this in the type system?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.