Skip to content

Commit 321b938

Browse files
committed
Initialise
0 parents  commit 321b938

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+12362
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*~
2+
*.ttc
3+
*.ttm
4+
*.o
5+
*.d
6+
*.a
7+
*.dll
8+
9+
# Editor/IDE Related
10+
.\#* # Emacs swap file
11+
*~ # Vim swap file
12+
*.swo
13+
*.swp
14+
# VS Code
15+
.vscode/*
16+
17+
/build
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Decidable.Equality
2+
3+
-- This is the (simplified) definition of names in Core.TT
4+
data Name : Type where
5+
UN : String -> Name -- user written name
6+
MN : String -> Int -> Name -- machine generated name
7+
8+
-- 1. Write an Eq instance for Name
9+
-- (sorry, it's not derivable yet!)
10+
Eq Name where
11+
-- ...
12+
13+
-- 2. Sometimes, we need to compare names for equality and use a proof that
14+
-- they're equal. So, implement the following
15+
nameEq : (x : Name) -> (y : Name) -> Maybe (x = y)
16+
17+
-- 3. (Optional, since we don't need this in Idris 2, but it's a good
18+
-- exercise to see if you can do it!) Implement decidable equality, so you
19+
-- also have a proof if names are *not* equal.
20+
DecEq Name where
21+
decEq x y = ?decEq_rhs
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
data Name : Type where
3+
UN : String -> Name -- user written name
4+
MN : String -> Int -> Name -- machine generated name
5+
6+
-- In the term representation, we represent local variables as an index into
7+
-- a list of bound names:
8+
data IsVar : Name -> Nat -> List Name -> Type where
9+
First : IsVar n Z (n :: ns)
10+
Later : IsVar n i ns -> IsVar n (S i) (m :: ns)
11+
12+
-- And, sometimes, it's convenient to manipulate variables separately.
13+
-- Note the erasure properties of the following definition (it is just a Nat
14+
-- at run time)
15+
data Var : List Name -> Type where
16+
MkVar : {i : Nat} -> (0 p : IsVar n i vars) -> Var vars
17+
18+
-- 1. Remove all references to the most recently bound variable
19+
dropFirst : List (Var (v :: vs)) -> List (Var vs)
20+
21+
-- 2. Add a reference to a variable in the middle of a scope - we'll need
22+
-- something like this later.
23+
-- Note: The type here isn't quite right, you'll need to modify it slightly.
24+
insertName : Var (outer ++ inner) -> Var (outer ++ n :: inner)
25+
26+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
-- 1. Prove that appending Nil is the identity
3+
-- (Note: this is defined in Data.List, but have a go yourself!)
4+
appendNilNeutral : (xs : List a) -> xs ++ [] = xs
5+
6+
-- 2. Prove that appending lists is associative.
7+
-- (Note: also defined in Data.List)
8+
appendAssoc : (xs : List a) -> (ys : List a) -> (zs : List a) ->
9+
xs ++ (ys ++ zs) = (xs ++ ys) ++ zs
10+
11+
-- A tree indexed by the (inorder) flattening of its contents
12+
data Tree : List a -> Type where
13+
Leaf : Tree []
14+
Node : Tree xs -> (x : a) -> Tree ys -> Tree (xs ++ x :: ys)
15+
16+
-- 3. Fill in rotateLemma. You'll need appendAssoc.
17+
rotateL : Tree xs -> Tree xs
18+
rotateL Leaf = Leaf
19+
rotateL (Node left n Leaf) = Node left n Leaf
20+
rotateL (Node left n (Node rightl n' rightr))
21+
= ?rotateLemma $ Node (Node left n rightl) n' rightr
22+
23+
-- 4. Complete the definition of rotateR
24+
rotateR : Tree xs -> Tree xs

TinyIdris-v1/Test/Nat.tidr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
data Nat : Type where
2+
Z : Nat
3+
S : Nat -> Nat
4+
5+
plus : Nat -> Nat -> Nat
6+
pat y : Nat =>
7+
plus Z y = y
8+
pat k : Nat, y : Nat =>
9+
plus (S k) y = S (plus k y)

TinyIdris-v1/Test/Vect.tidr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
data Nat : Type where
2+
Z : Nat
3+
S : Nat -> Nat
4+
5+
plus : Nat -> Nat -> Nat
6+
pat y : Nat =>
7+
plus Z y = y
8+
pat k : Nat, y : Nat =>
9+
plus (S k) y = S (plus k y)
10+
11+
data Vect : Nat -> Type -> Type where
12+
Nil : (a : Type) -> Vect Z a
13+
Cons : (a : Type) -> (k : Nat) ->
14+
a -> Vect k a -> Vect (S k) a
15+
16+
append : (a : Type) -> (n : Nat) -> (m : Nat) ->
17+
Vect n a -> Vect m a -> Vect (plus n m) a
18+
pat a : Type, k : Nat, ys : Vect k a =>
19+
append a Z k (Nil a) ys = ys
20+
pat a : Type, n : Nat, x : a, xs : Vect n a, k : Nat, ys : Vect k a =>
21+
append a (S n) k (Cons a n x xs) ys
22+
= Cons a (plus n k) x (append a n k xs ys)

0 commit comments

Comments
 (0)