Version française
Home     About     Download     Resources     Contact us    
Browse thread
OCaml object types vs record types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] OCaml object types vs record types
On 6/4/07, Raj B <rajb@rice.edu> wrote:
> Hi there
>
> I'm writing an application where I'd modeling objects as record
> types. However, I'd like to have a subtyping relation between them
> along with (occasional) coercion. For example,
>
> type obj = {name : string}
> type specialobj = {name: string; mutable value: int;...}
> and so on...
>

The pa_oo extension from Jacques Garrigue  does exactly this kind of things:

http://www.math.nagoya-u.ac.jp/~garrigue/code/ocaml.html
(works also in 3.10 but not released yet, contact me if you want it)

Example:

type obj = <name : string>
type specialobj = <name: string; value: int; set_value: int -> unit...>

let o = {| name = "foo"; mutable value = 42 |}
in o#name, o#value <- 43, o#value

Regards,

-- 
Nicolas Pouillard