Skip to content

Instantly share code, notes, and snippets.

@exterm
Created March 6, 2013 19:53
Show Gist options
  • Save exterm/5102479 to your computer and use it in GitHub Desktop.
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
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