Last active
August 29, 2015 14:12
-
-
Save AndrasKovacs/c45c0e005013dc468c76 to your computer and use it in GitHub Desktop.
Lifted list append is associative
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
| {-# LANGUAGE TypeOperators, PolyKinds, DataKinds, GADTs, TypeFamilies #-} | |
| import Data.Type.Equality | |
| type family (++) (xs :: [*]) (ys :: [*]) where | |
| '[] ++ ys = ys | |
| (x ': xs) ++ ys = x ': (xs ++ ys) | |
| data SList (xs :: [*]) where | |
| Nil :: SList '[] | |
| Succ :: SList xs -> SList (x ': xs) | |
| appAssoc :: | |
| SList xs -> SList ys -> SList zs -> | |
| (xs ++ (ys ++ zs)) :~: ((xs ++ ys) ++ zs) | |
| appAssoc Nil ys zs = Refl | |
| appAssoc (Succ xs) ys zs = | |
| case appAssoc xs ys zs of Refl -> Refl | |
| class WitnessList (xs :: [*]) where | |
| witness :: SList xs | |
| instance WitnessList '[] where | |
| witness = Nil | |
| instance WitnessList xs => WitnessList (x ': xs) where | |
| witness = Succ witness | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment