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
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 18 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago