Created
March 6, 2013 19:53
-
-
Save exterm/5102479 to your computer and use it in GitHub Desktop.
Example for Generalised Algebraic Datatypes in Haskell
Used to create a safe list type
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
data Safe a = Safe a | |
data NotSafe = NotSafe | |
data SafeList a b where | |
Nil :: SafeList a NotSafe | |
Cons :: a -> SafeList a b -> SafeList a (Safe b) | |
safeHead :: SafeList a (Safe b) -> a | |
safeHead (Cons x _) = x | |
-- safeHead Nil = ??? | |
-- safeHead is a total function! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment