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
27 weeks 2 days ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago