tags:

views:

43

answers:

3

I'm trying to write something 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 ?

+8  A: 

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; }
nlucaroni
I always interpreted it as the deconstruction of components of a single triple/tuple/... How are the two definitions different? Or, what implications does the difference mean? How does ocaml use them differently then?
nlucaroni
nlucaroni: I believe this is just syntax. Multiparameter types are just that - type parameterized by several parameters, compiler only needs to know how many parameters are present. Tuple types are different - they define a 'structure' of the value. Hope I didn't mess up badly with terminology :)
ygrek
+3  A: 

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 }
ygrek
+1  A: 

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.

M.S.