I can’t figure out how to fix this. I would have thought it could tell that both the pattern from the Call constructor and the pattern from the Lambda constructor were true at the same time since one is inside the other. I ‘just’ want it to copy the value u out of frame f into frame g, run the body, and then copy the return value v out of frame g into frame f. Is this possible? It seems to be GADTs getting in my way, and I don’t really understand them. The whole thing is on GitHub. And also a parser using it for editing mp3 ID3 metadata It uses one specification to both parse and format for saving the edited mp3s. I’ve got this
class Frame name value frame where
myget1 :: name -> frame -> value
myset1 :: name -> value -> frame -> frame
data Rule s t f r where
Call :: (Frame m u f, Frame n v f) => m -> Lambda s t g u v -> n -> Rule s t f v
data Lambda s t g u v where
Lambda :: (Frame j u g, Frame k v g) => j -> Rule s t g v -> k -> Lambda s t g u v
parse1 :: (Show str, BStringC tok str, Eq tok, Show tok, Ord tok) => Rule str tok frame res -> frame -> str -> IResult str tok frame res
... other clauses of parse1 ...
parse1 (Call m (Lambda j body k) n) f t =
case parse1 body (myset1 j (myget1 m f) undefined) t of
Done t1 g r1 -> Done t1 (myset1 n (myget1 k g) f) r1
... other clauses of parse1 ...
giving these errors:
• Could not deduce ‘Frame j value0 g’
arising from a use of ‘myset1’
from the context: (Show str, BStringC tok str, Show tok, Ord tok)
bound by the type signature for:
parse1 :: forall str tok frame res.
(Show str, BStringC tok str, Eq tok, Show tok, Ord tok) =>
Rule str tok frame res -> frame -> str -> IResult str tok frame res
at /home/brett/swissarmyknife/Parser5.hs:229:1-136
or from: (Frame m u frame, Frame n res frame)
bound by a pattern with constructor:
Call :: forall m u f n v s t g.
(Frame m u f, Frame n v f) =>
m -> Lambda s t g u v -> n -> Rule s t f v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:9-34
or from: (Frame j u g, Frame k res g)
bound by a pattern with constructor:
Lambda :: forall j u g k v s t.
(Frame j u g, Frame k v g) =>
j -> Rule s t g v -> k -> Lambda s t g u v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:17-31
The type variable ‘value0’ is ambiguous
Relevant bindings include
body :: Rule str tok g res
(bound at /home/brett/swissarmyknife/Parser5.hs:349:26)
j :: j (bound at /home/brett/swissarmyknife/Parser5.hs:349:24)
• In the second argument of ‘parse1’, namely
‘(myset1 j (myget1 m f) undefined)’
In the expression: parse1 body (myset1 j (myget1 m f) undefined) t
In the expression:
case parse1 body (myset1 j (myget1 m f) undefined) t of
Done t1 g r1 -> Done t1 (myset1 n (myget1 k g) f) r1
and
• Could not deduce ‘Frame m value0 frame’
arising from a use of ‘myget1’
from the context: (Show str, BStringC tok str, Show tok, Ord tok)
bound by the type signature for:
parse1 :: forall str tok frame res.
(Show str, BStringC tok str, Eq tok, Show tok, Ord tok) =>
Rule str tok frame res -> frame -> str -> IResult str tok frame res
at /home/brett/swissarmyknife/Parser5.hs:229:1-136
or from: (Frame m u frame, Frame n res frame)
bound by a pattern with constructor:
Call :: forall m u f n v s t g.
(Frame m u f, Frame n v f) =>
m -> Lambda s t g u v -> n -> Rule s t f v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:9-34
or from: (Frame j u g, Frame k res g)
bound by a pattern with constructor:
Lambda :: forall j u g k v s t.
(Frame j u g, Frame k v g) =>
j -> Rule s t g v -> k -> Lambda s t g u v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:17-31
The type variable ‘value0’ is ambiguous
Relevant bindings include
f :: frame (bound at /home/brett/swissarmyknife/Parser5.hs:349:37)
m :: m (bound at /home/brett/swissarmyknife/Parser5.hs:349:14)
parse1 :: Rule str tok frame res
-> frame -> str -> IResult str tok frame res
(bound at /home/brett/swissarmyknife/Parser5.hs:230:1)
• In the second argument of ‘myset1’, namely ‘(myget1 m f)’
In the second argument of ‘parse1’, namely
‘(myset1 j (myget1 m f) undefined)’
In the expression: parse1 body (myset1 j (myget1 m f) undefined) t
and
• Could not deduce ‘Frame n value1 frame’
arising from a use of ‘myset1’
from the context: (Show str, BStringC tok str, Show tok, Ord tok)
bound by the type signature for:
parse1 :: forall str tok frame res.
(Show str, BStringC tok str, Eq tok, Show tok, Ord tok) =>
Rule str tok frame res -> frame -> str -> IResult str tok frame res
at /home/brett/swissarmyknife/Parser5.hs:229:1-136
or from: (Frame m u frame, Frame n res frame)
bound by a pattern with constructor:
Call :: forall m u f n v s t g.
(Frame m u f, Frame n v f) =>
m -> Lambda s t g u v -> n -> Rule s t f v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:9-34
or from: (Frame j u g, Frame k res g)
bound by a pattern with constructor:
Lambda :: forall j u g k v s t.
(Frame j u g, Frame k v g) =>
j -> Rule s t g v -> k -> Lambda s t g u v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:17-31
The type variable ‘value1’ is ambiguous
Relevant bindings include
f :: frame (bound at /home/brett/swissarmyknife/Parser5.hs:349:37)
n :: n (bound at /home/brett/swissarmyknife/Parser5.hs:349:34)
parse1 :: Rule str tok frame res
-> frame -> str -> IResult str tok frame res
(bound at /home/brett/swissarmyknife/Parser5.hs:230:1)
• In the second argument of ‘Done’, namely
‘(myset1 n (myget1 k g) f)’
In the expression: Done t1 (myset1 n (myget1 k g) f) r1
In a case alternative:
Done t1 g r1 -> Done t1 (myset1 n (myget1 k g) f) r1
and
• Could not deduce ‘Frame k value1 g’
arising from a use of ‘myget1’
from the context: (Show str, BStringC tok str, Show tok, Ord tok)
bound by the type signature for:
parse1 :: forall str tok frame res.
(Show str, BStringC tok str, Eq tok, Show tok, Ord tok) =>
Rule str tok frame res -> frame -> str -> IResult str tok frame res
at /home/brett/swissarmyknife/Parser5.hs:229:1-136
or from: (Frame m u frame, Frame n res frame)
bound by a pattern with constructor:
Call :: forall m u f n v s t g.
(Frame m u f, Frame n v f) =>
m -> Lambda s t g u v -> n -> Rule s t f v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:9-34
or from: (Frame j u g, Frame k res g)
bound by a pattern with constructor:
Lambda :: forall j u g k v s t.
(Frame j u g, Frame k v g) =>
j -> Rule s t g v -> k -> Lambda s t g u v,
in an equation for ‘parse1’
at /home/brett/swissarmyknife/Parser5.hs:349:17-31
The type variable ‘value1’ is ambiguous
Relevant bindings include
g :: g (bound at /home/brett/swissarmyknife/Parser5.hs:351:15)
k :: k (bound at /home/brett/swissarmyknife/Parser5.hs:349:31)
body :: Rule str tok g res
(bound at /home/brett/swissarmyknife/Parser5.hs:349:26)
• In the second argument of ‘myset1’, namely ‘(myget1 k g)’
In the second argument of ‘Done’, namely
‘(myset1 n (myget1 k g) f)’
In the expression: Done t1 (myset1 n (myget1 k g) f) r1