I'm trying to write somethin开发者_如何学JAVAg like this:
type 'a 'b xxx = {aaa: 'a: bbb: 'b: ccc: int};;
It does not compile. Is it just syntax error, or they don't allow multiple paramters on type ? Then why ?
In ML, multiple type parameters are written between parentheses and separated by commas, like this:
type ('a,'b) xxx = {aaa: 'a; bbb: 'b; ccc: int; }
Actually you can write like this, in revised syntax :
Objective Caml version 3.11.2
# #load "dynlink.cma";;
# #load "camlp4r.cma";;
Camlp4 Parsing version 3.11.2
# type xxx 'a 'b = { aaa : 'a; bbb: 'b; ccc: int};
type xxx 'a 'b = { aaa : 'a; bbb : 'b; ccc : int }
The type parameters are defined in the manual as:
type-params ::= type-param | ( type-param { , type-param } )
So, for a list of type parameters, it's a comma-separated list enclosed within parenthesis.
精彩评论