Display type and value using reason

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

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

gives:

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

This is not practical for language learning.

I'm considering switching to Reason, but how would you get the same information?

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

Try Reason does not display any type, and I'm not sure if REPL exists for Reason.

+5
source share
1 answer

rtop is a toplevel (REPL in OCaml-lingo) that comes with reason-cli , and it's really just a thin shell around utop . He will print this type:

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

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

enter image description here

+4
source

Source: https://habr.com/ru/post/1273580/


All Articles