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

3 days 6 hours ago

3 days 9 hours ago

3 days 13 hours ago

4 days 5 hours ago

4 days 16 hours ago

6 days 6 hours ago

6 days 8 hours ago

6 days 9 hours ago

6 days 13 hours ago

6 days 14 hours ago