Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying type and value with Reason

Tags:

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.

like image 515
Aristide Avatar asked Nov 22 '17 15:11

Aristide


1 Answers

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

like image 171
glennsl Avatar answered Oct 11 '22 20:10

glennsl