Simon Peyton-Jones, via Haskell-list:

I've finished my first attempt at implementing Generalised Algebraic

Data types in GHC. Ordinary algebraic data types are generalised to

allow you to write an explicit type signature for each constructor; for

example:

data Term a where
Lit :: Int -> Term Int
Succ :: Term Int -> Term Int
IsZero :: Term Int -> Term Bool
If :: Term Bool -> Term a -> Term a -> Term a

Notice that some of these constructors have return types that are not

just "Term a"... that's the whole point! Now you can write typed

evaluator for these terms:

eval :: Term a -> a
eval (Lit i) = i
eval (Succ t) = 1 + eval t
eval (IsZero i) = eval i == 0
eval (If b e1 e2) = if eval b then eval e1 else eval e2

This is implementation of the "wobbly types" we've discussed before in GHC, slated for release in version 6.4. Simon also give a pointer to Tim Sheard's site, as he's done a lot of related work. There I found an interesting looking paper on Omega, a language which takes the GADT idea even further.

## Recent comments

1 day 13 hours ago

1 day 14 hours ago

2 days 7 hours ago

6 days 2 hours ago

6 days 8 hours ago

6 days 10 hours ago

6 days 20 hours ago

1 week 1 day ago

1 week 2 days ago

1 week 2 days ago