This is a homework for a functional programming course.
- Standard data types:
- bool
- int
- string
- unit
- list
- option
- Standard binary and unary operators
- Recursive functions
- First-class functions with partial application and mutual recursion
- Closures
- Carrying
- Anonymous functions
- Nested let bingings
- Standard function for integer printing
- Pattern matching
- Active Patterns
- Explicit type annotations
- AST
- Parser
- Type inferencer / checker
- Interpreter
There is also implemented:
- REPL
- Property-based testing: parser ∘ prettyPrinter ≡ id (parser and prettyPrinter composition produce the same AST) with qcheck
-
Install opam
-
Install dependencies
opam init --bare
opam update
opam switch create Fsharp --packages=ocaml-variants.4.14.2+options,ocaml-option-flambda --yes
make depsOpam will suggest you to update your bash (zsh) configuration to automatically set up the environment.
- Run interpeter with
dune exec replAnd type
let (|Big|Small|) input = if input > 10 then Big(input) else Small(input);;
# val |Big|Small| : int -> Choice<Big (int), Small (int)> = <fun>
let f g x = match x with
| Big(x) -> Some(g x)
| _ -> None;;
# val f : (int -> '9) -> int -> '9 option = <fun>
let carried_f = f (fun x -> x * 2);;
# val carried_f : int -> int option = <fun>
carried_f 20;;
# val - : int option = Some 40
carried_f 5;;
# val - : int option = NoneOr from file (file must not contain ;; separator) with
dune exec repl -from input.fs