Unexpected failure.. (bug?)
From A Generic Abstract Syntax Model for Embedded Languages (paper)
infixr :->
infixl 1 :$
data Full a
data a :-> b
data AST dom sig where
Sym :: dom sig -> AST dom sig
(:$) :: AST dom (a :-> sig) -> AST dom (Full a) -> AST dom sig
class Binding dom where
viewVar :: dom a -> Maybe Integer
viewBnd :: dom (a :-> b) -> Maybe Integer
freeVars :: Binding dom => AST dom a -> [Integer]
freeVars = \case
Sym (a -> Just v) -> [v]
Sym (b -> Just v) :$ body -> undefined
where
(a, _) = (viewVar, undefined)
(_, b) = (undefined, viewBnd)
works, and so does
where
a = viewVar
b = viewBnd
but
where
(a, b) = (viewVar, viewBnd)
yields
tSvp.hs:20:5-31: error: …
• Could not deduce (Binding dom0)
from the context: Binding dom
bound by the type signature for:
freeVars :: Binding dom => AST dom a -> [Integer]
at /tmp/tSvp.hs:14:1-49
or from: Binding dom2
bound by the inferred type for ‘a’:
Binding dom2 => dom2 a1 -> Maybe Integer
at /tmp/tSvp.hs:20:5-31
The type variable ‘dom0’ is ambiguous
• When checking that the inferred type
a :: forall k k1 (dom :: * -> *) a (dom1 :: *
-> *) (a1 :: k) (b :: k1).
(Binding dom1, Binding dom) =>
dom a -> Maybe Integer
is as general as its inferred signature
a :: forall (dom :: * -> *) a.
Binding dom =>
dom a -> Maybe Integer
In an equation for ‘freeVars’:
freeVars
= \case {
Sym (a -> Just v) -> [v]
Sym (b -> Just v) :$ body -> undefined }
where
(a, b) = (viewVar, viewBnd)
tSvp.hs:20:5-31: error: …
• Could not deduce (Binding dom1)
from the context: Binding dom
bound by the type signature for:
freeVars :: Binding dom => AST dom a -> [Integer]
at /tmp/tSvp.hs:14:1-49
or from: Binding dom2
bound by the inferred type for ‘b’:
Binding dom2 => dom2 (a1 :-> b) -> Maybe Integer
at /tmp/tSvp.hs:20:5-31
The type variable ‘dom1’ is ambiguous
• When checking that the inferred type
b :: forall k k1 (dom :: * -> *) a (dom1 :: *
-> *) (a1 :: k) (b :: k1).
(Binding dom1, Binding dom) =>
dom1 (a1 :-> b) -> Maybe Integer
is as general as its inferred signature
b :: forall k k1 (dom :: * -> *) (a :: k) (b :: k1).
Binding dom =>
dom (a :-> b) -> Maybe Integer
In an equation for ‘freeVars’:
freeVars
= \case {
Sym (a -> Just v) -> [v]
Sym (b -> Just v) :$ body -> undefined }
where
(a, b) = (viewVar, viewBnd)
Compilation failed.
Is this intentional?