Interpreter for a subset of OCaml with support for typed effects.
OCamlTyEff tracks the (side) effects of every function and represents them in the function’s type.
OCamlTyEff has 3 basic built-in effects: console, exn, ref. Intepreter automatically infers these effects if they occur in a function:
# fun () -> print_endline "Hello, World!";;
- : unit -[console]-> unit = <fun>
# fun x -> if x = 0 then raise Invalid_argument else x * 2;;
- : int -[exn _Invalid_argument]-> int = <fun>
# fun x -> global := x; 8 / x;;
- : int -[ref, exn _Division_by_zero]-> int = <fun>exn effect can be lifted using try ... with:
# ( / );;
- : int -> int -[exn _Division_by_zero]-> int = <fun>
# let safe_div x y = try x / y with Division_by_zero -> 0;;
safe_div : int -> int -> int = <fun>Many functions are polymorphic in their effect.
For example, list_map applies provided function to each element of a list. As such, the effect of list_map depends on the effect of provided function:
# list_map;;
- : ('a -'e-> 'b) -> 'a list -'e-> 'b list = <fun>
# list_map id;;
- : 'a list -> 'a list = <fun>
# list_map print_endline;;
- : string list -[console]-> unit list = <fun>The type system for effects is based on Koka programming language. Please refer to its documentation for more information on effect types.
Take a look at provided examples to get a grasp of what's supported.
First install the dependencies using opam:
opam install --locked --deps-only -t -y .Then build and run REPL using dune:
dune exec replTests can be run by executing:
dune runtestDistributed under the MIT License. See LICENSE for more information.
