GADT question
J. Garrett Morris
trevion at gmail.com
Mon Oct 10 13:06:28 EDT 2005
Hello,
I've been attempting to use GADTs to create a small domain specific
language, and I'm running into an odd problem. Adding one case to the
example at the beginning of the Wobbly types paper:
data Term :: * -> *
where Lit :: a -> Term a
Inc :: Term Int -> Term Int
IsZ :: Num a => Term a -> Term Bool
Div :: Fractional a => Term a -> Term a -> Term a
If :: Term Bool -> Term a -> Term a -> Term a
and extending the eval function accordingly:
eval :: Term a -> a
eval (Lit i) = i
eval (Inc t) = eval t + 1
eval (IsZ t) = eval t == 0
eval (Div t u) = eval t / eval u
eval (If cond cons alt) = if eval cond then eval cons else eval alt
I get an error "No instance for (Fractional a) arising from the use of
'/'" This seems odd to me, since Div is constrained to have
fractional arguments. Is there something obvious I'm missing?
Thanks,
/g
More information about the Glasgow-haskell-users
mailing list