• Could not deduce: RightComb (r : rs) ~ 'TagPair r (RightComb rs)
from the context: input ~ (r : rs)
bound by a pattern with constructor:
:& :: forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs),
in a case alternative
at src/Michelson/Example.hs:18:3-9
Expected type: Exp (RightComb input)
Actual type: Exp ('TagPair r (RightComb rs))
• In the expression: EPair a (rightComb xs)
In a case alternative: a :& xs -> EPair a (rightComb xs)
In the expression:
\case
a :& b :& RNil -> EPair a b
a :& xs -> EPair a (rightComb xs)
• Relevant bindings include
xs :: Rec Exp rs (bound at src/Michelson/Example.hs:18:8)
a :: Exp r (bound at src/Michelson/Example.hs:18:3)
|
18 | a :& xs -> EPair a (rightComb xs)
| ^^^^^^^^^^^^^^^^^^^^^^
Last active
January 18, 2021 16:02
-
-
Save dcastro/ef6bfef0b72d67f3efe86044bcb23655 to your computer and use it in GitHub Desktop.
TyFam inductive case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Vinyl (Rec(..)) | |
data Tag = TagInt | TagPair Tag Tag | |
data Exp (t :: Tag) where | |
EInt :: Int -> Exp 'TagInt | |
EPair :: Exp t1 -> Exp t2 -> Exp ('TagPair t1 t2) | |
type family RightComb (tags :: [Tag]) :: Tag where | |
RightComb '[ x, y ] = 'TagPair x y | |
RightComb (x ': xs) = 'TagPair x (RightComb xs) | |
-- Turns: | |
-- EInt 1 :& EInt 2 :& EInt 3 :& RNil | |
-- Into: | |
-- EPair (EInt 1) (EPair (EInt 2) (EInt 3)) | |
rightComb :: forall (tags :: [Tag]) . Rec Exp tags -> Exp (RightComb tags) | |
rightComb = \case | |
a :& b :& RNil -> EPair a b | |
a :& xs -> EPair a (rightComb xs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: this works: