How to create a type with multiple parameters in OCaml?

I am trying to create a type with several type parameters. I know how to create a type with one parameter:

type 'a foo = 'a * int 

But I need to have two parameters so that I can parameterize the 'int' part. How can i do this?

+4
source share
2 answers

The way to do this is:

 type ('a, 'b) foo = 'a * 'b 

Type parameters are not specified, so you need to provide them as a tuple as one parameter. A good example of this is the Hashtbl module:

 type ('a, 'b) t 

A hash table type from type 'a for input "b.

+5
source

# type ('a, 'b) couple = 'a * 'b ;;

For instance...

+2
source

All Articles