开发者

multiple parameters type

开发者 https://www.devze.com 2022-12-31 17:43 出处:网络
I\'m trying to write somethin开发者_如何学JAVAg like this: type \'a \'b xxx = {aaa: \'a: bbb: \'b: ccc: int};;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消