├── .gitignore ├── LICENSE.md ├── Makefile ├── README.md ├── doc └── pdf │ └── slides.pdf └── src ├── STLC.agda ├── STLC.hs └── STLC.idr /.gitignore: -------------------------------------------------------------------------------- 1 | *.agdai 2 | *.hi 3 | *.ibc 4 | *.o 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT X11 license 2 | =============== 3 | 4 | Copyright © 2015 Miëtek Bak. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | *The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.* 11 | 12 | Except as contained in this notice, the names of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in the Software without prior written authorization. 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all agda haskell idris 2 | all: agda haskell idris 3 | 4 | .PHONY: clean agda-clean haskell-clean idris-clean 5 | clean: agda-clean haskell-clean idris-clean 6 | 7 | 8 | agda := $(shell find src -type f -name '*.agda') 9 | agdai := $(patsubst %.agda,%.agdai,$(agda)) 10 | 11 | agda: $(agdai) 12 | 13 | %.agdai: %.agda 14 | agda --safe -i src $< 15 | 16 | agda-clean: 17 | rm -f $(agdai) 18 | 19 | 20 | idr := $(shell find src -type f -name '*.idr') 21 | ibc := $(patsubst %.idr,%.ibc,$(idr)) 22 | 23 | idris: $(ibc) 24 | 25 | %.ibc: %.idr 26 | idris --check -i src $< 27 | 28 | idris-clean: 29 | rm -f $(ibc) 30 | 31 | 32 | hs := $(shell find src -type f -name '*.hs') 33 | hi := $(patsubst %.hs,%.hi,$(hs)) 34 | o := $(patsubst %.hs,%.o,$(hs)) 35 | 36 | haskell: $(hi) $(o) 37 | 38 | %.hi %.o: %.hs 39 | ghc --make -Wall -isrc $< 40 | 41 | haskell-clean: 42 | rm -f $(hi) $(o) 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | _haskell-exchange-2015_ 2 | ======================= 3 | 4 | Materials for my [Haskell eXchange 2015 talk](https://skillsmatter.com/skillscasts/6664-build-your-own-proof-assistant), including the [slides](doc/pdf/slides.pdf). 5 | 6 | See [_formal-logic_](https://github.com/mietek/formal-logic) for more formalisations. 7 | 8 | 9 | Usage 10 | ----- 11 | 12 | To check all files automatically: 13 | 14 | ``` 15 | $ make 16 | ``` 17 | 18 | To load a particular file for interactive use: 19 | 20 | ``` 21 | $ agda --safe -I -i src src/FILE.agda 22 | ``` 23 | 24 | ``` 25 | $ ghci -Wall -isrc src/FILE.hs 26 | ``` 27 | 28 | ``` 29 | $ idris -i src src/FILE.idr 30 | ``` 31 | 32 | Tested with Agda 2.4.2.3, Idris 0.9.19, and GHC 7.8.4. 33 | 34 | 35 | About 36 | ----- 37 | 38 | Made by [Miëtek Bak](https://mietek.io/). Published under the [MIT X11 license](LICENSE.md). 39 | -------------------------------------------------------------------------------- /doc/pdf/slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mietek/haskell-exchange-2015/3f8e19674283d64d6c7e50f66a3e8f33138e9195/doc/pdf/slides.pdf -------------------------------------------------------------------------------- /src/STLC.agda: -------------------------------------------------------------------------------- 1 | -- Minimal implicational logic, PHOAS approach, initial encoding 2 | 3 | module STLC where 4 | 5 | 6 | -- Types 7 | 8 | infixr 0 _=>_ 9 | 10 | data Ty : Set where 11 | UNIT : Ty 12 | _=>_ : Ty -> Ty -> Ty 13 | 14 | 15 | -- Context 16 | 17 | Cx : Set1 18 | Cx = Ty -> Set 19 | 20 | 21 | -- Terms 22 | 23 | infixl 1 _$_ 24 | 25 | data Tm (tc : Cx) : Ty -> Set 26 | where 27 | var : forall {a} -> tc a 28 | ---------- 29 | -> Tm tc a 30 | 31 | lam : forall {a b} -> (tc a -> Tm tc b) 32 | --------------------- 33 | -> Tm tc (a => b) 34 | 35 | _$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a 36 | ---------------------------- 37 | -> Tm tc b 38 | 39 | T : Ty -> Set1 40 | T a = forall {tc} -> Tm tc a 41 | 42 | 43 | -- Example theorems 44 | 45 | I : forall {a} -> T (a => a) 46 | I = lam \x -> 47 | var x 48 | 49 | K : forall {a b} -> T (a => b => a) 50 | K = lam \x -> 51 | lam \_ -> 52 | var x 53 | 54 | S : forall {a b c} -> T ((a => b => c) => (a => b) => a => c) 55 | S = lam \f -> 56 | lam \g -> 57 | lam \x -> 58 | (var f $ var x) $ (var g $ var x) 59 | 60 | SKK : forall {a} -> T (a => a) 61 | SKK {a = a} = S {b = a => a} $ K $ K 62 | -------------------------------------------------------------------------------- /src/STLC.hs: -------------------------------------------------------------------------------- 1 | -- Minimal implicational logic, PHOAS approach, initial encoding 2 | 3 | {-# LANGUAGE DataKinds, GADTs, KindSignatures, Rank2Types, Safe, TypeOperators #-} 4 | 5 | module STLC where 6 | 7 | 8 | -- Types 9 | 10 | infixr 0 :=> 11 | 12 | data Ty :: * where 13 | UNIT :: Ty 14 | (:=>) :: Ty -> Ty -> Ty 15 | 16 | 17 | -- Context 18 | 19 | -- NOTE: Haskell does not support kind synonyms 20 | -- type Cx = Ty -> * 21 | 22 | 23 | -- Terms 24 | 25 | infixl 1 :$ 26 | 27 | data Tm :: (Ty -> *) -> Ty -> * 28 | where 29 | Var :: tc a 30 | ---------- 31 | -> Tm tc a 32 | 33 | Lam :: (tc a -> Tm tc b) 34 | -------------------- 35 | -> Tm tc (a :=> b) 36 | 37 | (:$) :: Tm tc (a :=> b) -> Tm tc a 38 | ----------------------------- 39 | -> Tm tc b 40 | 41 | type T a = forall tc. Tm tc a 42 | 43 | 44 | -- Example theorems 45 | 46 | aI :: T (a :=> a) 47 | aI = Lam $ \x -> 48 | Var x 49 | 50 | aK :: T (a :=> b :=> a) 51 | aK = Lam $ \x -> 52 | Lam $ \_ -> 53 | Var x 54 | 55 | aS :: T ((a :=> b :=> c) :=> (a :=> b) :=> a :=> c) 56 | aS = Lam $ \f -> 57 | Lam $ \g -> 58 | Lam $ \x -> 59 | (Var f :$ Var x) :$ (Var g :$ Var x) 60 | 61 | tSKK :: T (a :=> a) 62 | tSKK = aS :$ aK :$ aK 63 | -------------------------------------------------------------------------------- /src/STLC.idr: -------------------------------------------------------------------------------- 1 | -- Minimal implicational logic, PHOAS approach, initial encoding 2 | 3 | module STLC 4 | 5 | %default total 6 | 7 | 8 | -- Types 9 | 10 | infixr 0 :=> 11 | 12 | data Ty : Type where 13 | UNIT : Ty 14 | (:=>) : Ty -> Ty -> Ty 15 | 16 | 17 | -- Context 18 | 19 | Cx : Type 20 | Cx = Ty -> Type 21 | 22 | 23 | -- Terms 24 | 25 | infixl 1 :$ 26 | 27 | data Tm : Cx -> Ty -> Type 28 | where 29 | var : tc a 30 | ---------- 31 | -> Tm tc a 32 | 33 | lam : (tc a -> Tm tc b) 34 | -------------------- 35 | -> Tm tc (a :=> b) 36 | 37 | (:$) : Tm tc (a :=> b) -> Tm tc a 38 | ---------------------------- 39 | -> Tm tc b 40 | 41 | T : Ty -> Type 42 | T a = {tc : Cx} -> Tm tc a 43 | 44 | 45 | -- Example theorems 46 | 47 | I : T (a :=> a) 48 | I = lam $ \x => 49 | var x 50 | 51 | K : T (a :=> b :=> a) 52 | K = lam $ \x => 53 | lam $ \_ => 54 | var x 55 | 56 | S : T ((a :=> b :=> c) :=> (a :=> b) :=> a :=> c) 57 | S = lam $ \f => 58 | lam $ \g => 59 | lam $ \x => 60 | (var f :$ var x) :$ (var g :$ var x) 61 | 62 | SKK : T (a :=> a) 63 | SKK {a} = 64 | S {b = a :=> a} :$ K :$ K 65 | --------------------------------------------------------------------------------