Chris Ford (@ctford)
“Arthur Dent” : String
7 : Integer
String : Typenot : Bool -> Bool
(“foo”, 23) : (String, Integer)
Left 9 : Either Integer bidentity : a -> a
identity x = xHaskell Curry
William Howard
apply : (a -> b) -> a -> b
apply f x = f xIdris> apply chr 65
'A' : CharIdris> apply chr 66
'B' : Charchr : Integer -> Charcomp : (a->b) -> (b->c) -> (a->c)
comp f g x = g (f x)Idris> comp length (7==)
_ : List a -> Boollength : List a -> Integer
(==3) : Integer -> Boolconjunction : a -> b -> (a, b)
conjunction x y = (x, y)disjunctionl : a -> Either a b
disjunctionl x = Left xdisjunctionr : b -> Either a b
disjunctionr y = Right ya→a
(a→b)→a→b
a→b→(a, b)
(a, b) → b
a→b
(a→b)→(b→a)
Not : Type -> Type
Not p = p -> FalsityFalsity : Type
Falsity = Voidsecond : Not (Either a b) -> (Not a, Not b)
second f = (f . Left, f . Right)first : Either (Not a) (Not b) -> Not (a, b)
first (Left f) (x, _) = f x
first (Right g) (_, y) = g ysecondInverse : (Not a, Not b) -> Not (Either a b)
secondInverse (f, _) (Left x) = f x
secondInverse (_, g) (Right y) = g yEverythingIsTrue : Type
EverythingIsTrue = (a : Type) -> aCantProveEverything : Not EverythingIsTrue
CantProveEverything f = f FalsityNullPointerException
council.office.Lock.acquire (Lock.java:42)
council.office.FilingCabinet.find (FilingCabinet.java:42)
council.office.Leopard.beware (Leopard.java:42)
council.office.Lavatory.find (Lavatory.java:42)
council.office.Cellar.find (Cellar.java:42)
council.office.Consultation.post (Consultation.java:42)
council.policy.Bypass.plan (Bypass.java:42)
council.policy.ExpansionManager.execute (ExpansionManager.java:42)
council.policy.Budget.spend (Budget.java:42)Haskell> head []
*** Exception: Prelude.head:
*** empty listHaskell> last [1..]
*** Interrupted.head : Vect (n + 1) a -> a
head (x::_) = xIdris> head []
Can't unify Vect 0 a
with Vect (n + 1) iTypeoops : a -> b
oops x = oops xdata Even : Nat -> Type where
Zero : Even 0
Next : Even n -> Even (n + 2)Zero : Even 0
Next (Next (Next Zero)) : Even 6add : Even m -> Even n -> Even (m + n)
add Zero y = y
add (Next x) y = Next (add x y)fortyTwoIsEven : Even 42
fortyTwoIsEven = mul 21 (Next Zero)
where
mul : (n:Nat) -> Even m -> Even (n*m)
mul Z _ = Zero
mul (S n) e = add e (mul n e)threeAintEven : Not (Even 3)
threeAintEven (Next e) with (e)
| (Next _) impossible
| Zero impossibleLifeTheUniverseAndEverything
→
Even 42
Edwin Brady
Programming in Idris: A Tutorial
idris-lang.org
Brian McKenna
EvenOdd in Agda, Idris, Haskell, Scala
brianmckenna.org
Philip Wadler
Propositions as Types
wadler.blogspot.co.uk