I need to store a reference to a function. I know that it’s an async function, but I don’t know and don’t care about the arguments it wants.
How do I type this? I thought 'a. 'a would be of help here but it isn’t.
I need to store a reference to a function. I know that it’s an async function, but I don’t know and don’t care about the arguments it wants.
How do I type this? I thought 'a. 'a would be of help here but it isn’t.
I think you do care about the arguments, because at some point you’re going to call the function, right? Otherwise, why store it?
If you know the arguments at the point of storing it, but just don’t want to evaluate it, just wrap it in a unit => unit
function. If you don’t know at that point, but know the reference will be passed to a caller that does know, you can use an idiom called “universal values” to make an opaque value that is later recoverable. Here’s one implementation of that, in OCaml: Types as first class citizens in OCaml - #3 by ivg - Learning - OCaml (edit: sorry, the first link I posted was to one of Jane Street’s puzzles, not an actual implementation)
If you really don’t care, because this is going to be used in an interop scenario where you’re not going to call the function yourself, then there’s no point in knowing it’s a function either. Just cast it into an opaque type:
type opaqueFn
external opaqueify: (_ => _) => opaqueFn = "%identity"