I'm trying to learn ReasonML, and I'm doing some koans to help me with that task. One of the koans I'm trying to code is about asking for the type of a list after converting it to an array. I know that there are operators in some languages like Haskell (:t) where we can ask for the type of a variable. Is there any equivalent to :t for ReasonML? Or it shouldn't make sense to check if Array.of_list returns an array because the compiler ensures that...
I don't know much about Reason, but utop (an improved OCaml REPL) provides the #typeof directive to inspect the type of an expression:
let a = 42;;
val a : int = 42
#typeof "a";;
val a : int
Note that this is only a REPL tool. In OCaml, types are not available on runtime: they are stripped during compilation. You can learn more about the OCaml compilation process here.
As pointed out by @Rizo in the comments, there also is the #show directive, which is even available in the standard OCaml REPL:
let a = 43;;
val a : int = 43
#show a;;
val a : int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With