Skip to content

Instantly share code, notes, and snippets.

@AndrasKovacs
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save AndrasKovacs/c45c0e005013dc468c76 to your computer and use it in GitHub Desktop.

Select an option

Save AndrasKovacs/c45c0e005013dc468c76 to your computer and use it in GitHub Desktop.
Lifted list append is associative
{-# 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