Created
April 11, 2014 23:14
-
-
Save esmooov/10508956 to your computer and use it in GitHub Desktop.
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
-- GOAL: push values of type Either a b to a Stack and maintain a type-level | |
-- count of Left (n) and Right (m) cases | |
data Stack a b = MkStack (n : Nat ** (m : Nat ** Vect (n + m) (Either a b))) | |
push : Either a b -> Stack a b -> Stack a b | |
push (Left l) (MkStack (n ** (m ** v))) = MkStack ((S n) ** (m ** (Left l :: v))) | |
push (Right r) (MkStack (n ** (m ** v))) = MkStack (n ** ((S m) ** v')) | |
where v' : Vect (n + S (m)) (Either a b) | |
v' = rewrite (sym $ plusSuccRightSucc n m) in Right r :: v | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment