Created
August 14, 2015 16:45
-
-
Save blt/f3efbbb7e501ab67f58f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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