Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Troublesome nodes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-18 (02:27)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Troublesome nodes
From: Dario Teixeira <>

> Thanks for the clarification, Jacques.  So I guess my initial interpretation
> of 'private' was correct.  But is 'private' also applicable when a type
> is declared using a constraint?  In my Node module, for example, type 't'
> is declared abstract in the signature:
> type (+'a, 'b) t constraint 'a = [< super_node_t ]
> In the implementation, the type is declared as follows:
> type (+'a, 'b) t = 'a constraint 'a = [< super_node_t ]
> Is it possible in this case to make signature equal to the implementation
> except for a 'private' declaration?  (Being able to pattern-match on values
> of type 't' would be very handy, that is why I would prefer to use 'private'
> instead of making the type fully abstract).
> Note: I am running Ocaml 3.11+dev12.  Jeremy just sent a message where
> he reports that the compiler behaviour in this matter changed between
> 3.10 and 3.11.

This is indeed possible in 3.11, due to the addition of private
abbreviations. Note however that the behaviour of private
abbreviations is not as transparent as private types or rows: the only
practical difference between an abstract type and a private
abbreviation is that you can explicitely coerce from the private
abbreviation to its definition. You cannot use pattern matching
directly without coercion.

So if you write

  type (+'a, 'b) t = private 'a constraint 'a = [< super_node_t ]

then you must write (x : (_,_) t :> [> ]) if you want to use pattern
matching on x.

Another side-effect of the addition of private abbreviations is that
now the distinction between private rows and private abbreviations is
syntactic. In particular

  type (+'a, 'b) t = private 'a constraint 'a = [< super_node_t ]

defined a private row in 3.10, but it is a private abbreviation in 3.11
(with of course a different semantics).
If you need the private row semantics, you should now write it as

  type (+a, 'b) t = private [< super_node_t] as 'a

which is more intuitive anyway.

Jacques Garrigue