Skip to content

Instantly share code, notes, and snippets.

@blt
Created August 14, 2015 16:45
Show Gist options
  • Save blt/f3efbbb7e501ab67f58f to your computer and use it in GitHub Desktop.
Save blt/f3efbbb7e501ab67f58f to your computer and use it in GitHub Desktop.
> 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