Created
August 27, 2012 10:41
-
-
Save kmels/3487350 to your computer and use it in GitHub Desktop.
GHC 7.4.1
This file contains 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 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