For debugging purposes I'd like to have a function in OCaml that converts to string arbitrary type, the debugger currently has one, but it'd be cool to have one.
The sexplib library would be perfect, but the fact is that I can't modify all the types I need to add with sexp
, and I can't use camlp4 either.
Is there any such function? (It won't be on production code so I accept dirty solutions)
Something like Haskell's Show
typeclass would be exactly what I mean.
Thanks for your time
Use the Function() Constructor to create a function from the string. It accepts any number of arguments(in form of string). Last one should be the body of the function. In this example, Only the body of the function is passed which is returning a value.
According to the TypeScript docs: void represents the return value of functions which don't return a value. Whenever you see a function returning void , you are explicitly told there is no return value. All functions with no return value have an inferred return type of void .
The Std module in Batteries Included provides a dump
function which converts arbitrary types to readable strings. It is somewhat limited - as it does not know about types, it cannot print constructors for variant types properly and replaces them with numbers - but it can still be pretty helpful. Since type information is not available at runtime, that's about as good as you can do. The debugger and toplevel use compiler trickery to obtain better representations, but that is difficult if not impossible to do in a general library.
I seem to remember also seeing a more sophisticated dumping library somewhere, but I do not recall where.
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