How to create a record type of more than one polymorphic variable
type 'a item = { name:string; quantity:'a };;
This is the definition of polymorphic type described in the Ocaml class. I'm trying to extend this type to have more than one polymorphic variable in the element type, for example:
type 'a item = { name:string; quantity:'a; price:'b };;
But I am getting an error with unbound b value. So what should be the type of record type for more than one polymorphic variable?
+3
Fasna
source
to share
1 answer
Try
type ('a,'b) item = { name:string; quantity:'a; price:'b };;
As you might guess, you need to list each type variable on the left side. You did it for 'a
, it's only natural for 'b
.
+6
Théo Winterhalter
source
to share