I'm doing so fairly fun stuff with GHC 7.8, but have ran in to a bit of a problem. I have the following:
mkResultF :: Eq k => Query kvs ('KV k v) -> k -> ResultF (Reverse kvs) (Maybe v)
mkResultF Here key = ResultComp (pure . lookup key)
mkResultF q@(There p) key =
case mkResultF p key of
ResultFId a -> pure a
ResultComp c ->
ResultComp $ \foo ->
case c foo of
ResultFId a -> pure a
ResultComp c ->
ResultComp $ \foo ->
case c foo of
ResultFId a -> pure a
Clearly there is something to abstract here, but I can't quite work out how to do it. When I try the following:
mkResultF :: Eq k => Query kvs ('KV k v) -> k -> ResultF (Reverse kvs) (Maybe v)
mkResultF Here key = ResultComp (pure . lookup key)
mkResultF q@(There p) key = magic (mkResultF p key)
magic :: ResultF (Reverse kvs) (Maybe v) -> ResultF (Reverse kvs ++ '[('KV x y)]) (Maybe v)
magic (ResultFId a) = pure a
magic (ResultComp c) = ResultComp (\foo -> magic (c foo))
This feels like an "obvious" solution, but it doesn't type check:
Could not deduce (kvs2 ~ Reverse kvs0)
from the context (Reverse kvs ~ ('KV k v1 : kvs2))
bound by a pattern with constructor
ResultComp :: forall a k v (kvs :: [KV * *]).
([(k, v)] -> ResultF kvs a) -> ResultF ('KV k v : kvs) a,
in an equation for `magic'
at query-kv.hs:202:8-19
`kvs2' is a rigid type variable bound by
a pattern with constructor
ResultComp :: forall a k v (kvs :: [KV * *]).
([(k, v)] -> ResultF kvs a) -> ResultF ('KV k v : kvs) a,
in an equation for `magic'
at query-kv.hs:202:8
Expected type: ResultF (Reverse kvs0) (Maybe v)
Actual type: ResultF kvs2 (Maybe v)
Relevant bindings include
c :: [(k, v1)] -> ResultF kvs2 (Maybe v)
(bound at query-kv.hs:202:19)
In the first argument of `magic', namely `(c foo)'
In the expression: magic (c foo)
I'm really stuck on this. A full code listing with the starting code can be found here: https://gist.github.com/ocharles/669758b762b426a3f930