Last active
March 8, 2017 10:10
-
-
Save be5invis/db09534f6120f7825ee69a9920bfa856 to your computer and use it in GitHub Desktop.
PROPOSAL -- TT syntax
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
-- Totalscript syntax | |
Module -> Imports (Access? Declaration | Access Name | Access? OperatorDecl | Definition | Mutual)* | |
Access -> ("public" | "private") ("definition" | "function" | "lemma" | "theorem")? | |
Program -> (Declaration | Definition | Mutual)* | |
Imports -> Import* | |
Import -> "import" Name* "from" String | |
OperatorDecl -> "operator" Operator NumberLiteral ("left" | "right" | "none") "=" Access | |
DeclBlock -> "{" Declaration* "}" | |
DefBlock -> "{" Definition* "}" | |
ProgramBlock -> "{" Program "}" | |
Declaration -> SimpleDecl | InductiveDecl | InterfaceDecl | InstanceDecl | Coercion | |
SimpleDecl -> Name ":" Term | |
Param -> Name | "(" SimpleDecl ")" | |
InductiveDecl -> "inductive" SimpleDecl "where" DeclBlock | |
InterfaceDecl -> "interface" SimpleDecl Param+ "where" ProgramBlock | |
InstanceDecl -> "instance" (Name ":")? Term "where" ProgramBlock | |
Coercion -> "implicit" SimpleDecl | |
Definition -> (SimpleDef | ViewDef) ("where" ProgramBlock)? | |
SimpleDef -> Name Pattern* "=" Term | |
ViewDef -> Name Pattern* "with" Term+ DefBlock | |
Term -> If | Case | Expr1 | |
If -> "if" Term "then" Term "else" Term | |
Case -> "case" Term "of" "{" (Pattern "->" Term)* "}" | |
Expr1 -> Expr | |
| Param "->" Expr1 # Pi | |
| Expr "|" Expr1 # Interface Pi | |
| "(" SimpleDecl ("&" Expr1)+ ")" # Sigma | |
| Expr "<|" Expr1 # Low-priority call | |
| Expr1 "|>" Expr # Low-priority call, RTL | |
Expr -> Factor | Expr InfixL Factor | Factor InfixR Factor | |
Factor -> Primitive | Factor Primitive | |
Primitive -> Access | Literal | Do | Tactic | "(" Term ")" | "[" Term* "]" | |
Access -> Name | Access "." Name | |
Do -> "do" "{" (Pattern "<-" Term | Term)* "}" | |
Tactic -> ("tactic" | "proof") "{" (Pattern "<-" Term | Term)* "}" | |
Pattern -> Name | Name Pattern* | "(" Pattern ")" | "(" Name "|" Pattern ")" | |
Name -> ...... | |
Literal -> ...... |
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
inductive Tree : Type -> Type where { | |
Leaf : a -> Tree a | |
Branch : a -> Tree a -> Tree a -> Tree a | |
} | |
public instance Eq a | Eq (Tree a) where { | |
equal (Leaf a) (Leaf b) = equal a b | |
equal (Branch x1 l1 r1) (Branch x2 l2 r2) = (equal x1 x2) && (equal l1 l2) && (equal r1 r2) | |
equal p q = false | |
} | |
operator (@) 500 right = map | |
interface Functor (f : Type -> Type) where { | |
map : (a -> b) -> f a -> f b | |
} | |
public instance (Functor Tree) where { | |
map f (Leaf a) = Leaf (f a) | |
map f (Branch x l r) = Branch (f x) (map f l) (map f r) | |
} | |
public flipTree : Tree a -> Tree a | |
flipTree (x | Leaf a) = x | |
flipTree (Branch x l r) = Branch x (flipTree r) (flipTree l) | |
theorem flipTreeSym (t : Tree a) -> t === (flipTree <| flipTree a) | |
flipTreeSym = proof { | |
a <- intro | |
t <- intro | |
induct t | |
refl | |
rewrite ind_Branch_l | |
rewrite ind_Branch_r | |
refl | |
} |
Author
be5invis
commented
Mar 8, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment