Skip to content

Instantly share code, notes, and snippets.

@kmels
Created August 27, 2012 10:41
Show Gist options
  • Save kmels/3487350 to your computer and use it in GitHub Desktop.
Save kmels/3487350 to your computer and use it in GitHub Desktop.
GHC 7.4.1
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
data Expr :: * -> * where
Int :: Int -> Expr Int
Bool :: Bool -> Expr Bool
IsZero :: Expr Int -> Expr Bool
-- Plus :: (* -> *) -> (* -> *) -> (* ->
If :: Expr Bool -> Expr a -> Expr a -> Expr a
data Zero
data Succ a
type family Sum m n
type instance Sum Zero n = n
type instance Sum (Succ p) n = Succ(Sum p n)
data Nat :: * -> * where
Zero :: Nat Zero
Succ :: Nat n -> Nat (Succ n) --Why is the declaration of data Succ
a needed? (above)
data Vec :: * -> * -> * where
Nil :: Vec a Zero
Cons :: a -> Vec a n -> Vec a (Succ n)
instance (Show a,Show n) => Show (Vec a n) where
show Nil = "Vec0()"
show (Cons a Nil) = "Vec(" ++ (show a) ++ ")"
show (Cons a (Cons a2 v)) = "Vec(" ++ (show a) ++ "," ++ (show a2) ++ ")"
instance (Show a) -> Nat a where
show Zero = "Zero"
show (Succ a) = "Succ " ++ (show a)
vechead :: Vec a (Succ n) -> a
vechead (Cons x xs) = x
vectail :: Vec a (Succ n) -> Vec a n
vectail (Cons x xs) = xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment