5

The OCaml REPL displays the value and type of any expression. For instance, evaluating:

let rec map f = function
    | [] -> []
    | x::l -> f x :: map f l;;

Gives:

val map : ('a -> 'b) -> 'a list -> 'b list = <fun>

This is unvaluable for teaching the language.

I am considering switching to Reason, but how would you obtain the same informations?

let rec map = (f) =>
  fun
  | [] => []
  | [x, ...l] => [f(x), ...map(f, l)];

Try Reason doesn't display any type, and I am not sure if there exists a REPL for Reason.

glennsl
  • 28,186
  • 12
  • 57
  • 75
Aristide
  • 3,606
  • 2
  • 30
  • 50

1 Answers1

4

rtop is a toplevel (REPL in OCaml-lingo) that ships with reason-cli, and that is really just a thin wrapper around utop. It'll print the type like this:

let map: (('a) => 'b, list('a)) => list('b) = <fun>;

In VSCode, merlin will also give you the type of let bindings in a "CodeLens" displayed above each binding.

enter image description here

glennsl
  • 28,186
  • 12
  • 57
  • 75
  • Thanks, I had just played with TryReason and googled "Reason REPL". https://github.com/reasonml/reason-cli should make the trick. – Aristide Nov 22 '17 at 16:05