Update readme with identation syntax

This commit is contained in:
Martin Fredin 2023-04-03 12:31:29 +02:00
parent 077f76eb12
commit 5e5d258bb1

View file

@ -16,6 +16,8 @@ Using the bidirectional type checker: `./language -t bi example.crf`
The program to compile has to have the file extension `.crf` The program to compile has to have the file extension `.crf`
# Syntax and quirks # Syntax and quirks
See Grammar.pdf for the full syntax.
The syntactic requirements differ a bit using the different type checkers. The syntactic requirements differ a bit using the different type checkers.
The bidirectional type checker require explicit `forall` everywhere a type The bidirectional type checker require explicit `forall` everywhere a type
forall quantified type variable is declared. In the Hindley-Milner type checker forall quantified type variable is declared. In the Hindley-Milner type checker
@ -28,17 +30,18 @@ or inferrable.
Single line comments are written using `--` Single line comments are written using `--`
Multi line comments are written using `{-` and `-}` Multi line comments are written using `{-` and `-}`
Braches and semicolons are optional.
## Program ## Program
A program is a list of defs separated by semicolons, which in turn is either a bind, a signature, or a data types A program is a list of defs separated by semicolons, which in turn is either a bind, a signature, or a data types
`Program ::= [Def]` `Program ::= [Def]`
```hs ```hs
data Test () where { data Test () where
Test : Test () Test : Test ()
}; test : Int
test : Int ; test = 0
test = 0 ;
``` ```
## Bind ## Bind
@ -49,7 +52,7 @@ Both name and arguments have to start with lower case letters
`Bind ::= LIdent [LIdent] "=" Exp` `Bind ::= LIdent [LIdent] "=" Exp`
```hs ```hs
example x y = x + y ; example x y = x + y
``` ```
## Signature ## Signature
@ -59,7 +62,7 @@ The name has to start with a lowe case letter
`Sig ::= LIdent ":" Type` `Sig ::= LIdent ":" Type`
```hs ```hs
const : a -> b -> a ; const : a -> b -> a
``` ```
## Data type ## Data type
@ -72,12 +75,10 @@ The type can be any type for parsing, but only `TData` will type check.
The list of Inj is separated by white space. Using new lines is recommended for ones own sanity. The list of Inj is separated by white space. Using new lines is recommended for ones own sanity.
```hs ```hs
data Maybe (a) where { data Maybe (a) where
Nothing : Maybe (a) Nothing : Maybe (a)
Just : a -> Maybe (a) Just : a -> Maybe (a)
};
``` ```
The parens are necessary for every data type to make the grammar unambiguous. The parens are necessary for every data type to make the grammar unambiguous.
Thus in `data Bool () where ...` the parens *do* *not* represent Unit Thus in `data Bool () where ...` the parens *do* *not* represent Unit
@ -108,11 +109,11 @@ and foralls take one type variable followed by a type.
`TAll ::= "forall" LIdent "." Type` `TAll ::= "forall" LIdent "." Type`
```hs ```hs
exampleLit : Int ; exampleLit : Int
exampleVar : a ; exampleVar : a
exampleData : Maybe (a) ; exampleData : Maybe (a)
exampleFun : Int -> a ; exampleFun : Int -> a
exampleAll : forall a. forall b. a -> b ; exampleAll : forall a. forall b. a -> b
``` ```
## Expressions ## Expressions
@ -177,10 +178,9 @@ Case expression consist of a list semicolon separated list of Branches
`ECase ::= "case" Exp "of" "{" [Branch] "}"` `ECase ::= "case" Exp "of" "{" [Branch] "}"`
```hs ```hs
case xs of { case xs of
Cons x xs => 1; Cons x xs => 1
Nil => 0; Nil => 0
};
``` ```
### Branch ### Branch