Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 528

Check type of variable within a pattern match in OCaml

$
0
0

How do I check the type of a variable within a pattern matching in OCaml, version I currently use is 4.13, that is available online.

I found this post: OCaml: Type Checking ObjectsBut it doesnt really seem to solve the problem.

The sample code I tried is, here I want to get the type of x and depending of what type is it return something different

let typecheck x =   match #show x with   |"val x : int" -> "int"   |"val x : string" -> "string"   | _ -> "Undefined";;

But I get Error: Syntax error

Maybe I can re-input the output of the directive somehow in the program?


Viewing all articles
Browse latest Browse all 528

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>