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

How to forward the arguments of a constructor to a function in OCaml?

$
0
0

I have a type with constructors which take many arguments. When pattern matching on a constructor of this type, I would like to forward the arguments as a pack (maybe a tuple?), without having to retype them all.

This is code I would like to write:

type foo_t =  | FromInt of int * int  | FromFloat of floatlet sum_pair (a, b) =  a + b;;let f foo =  match foo with  | FromInt (a, b) as pair -> sum_pair pair  | FromFloat _ -> 0;;

The problem here is that pair is typed as foo_t instead of int * int. But sum_pair should expect a pair of ints and not a foo_t.


Viewing all articles
Browse latest Browse all 531

Trending Articles



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