Version française
Home     About     Download     Resources     Contact us    
Browse thread
restricting and hiding record fields for functors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Keiko Nakata <keiko@k...>
Subject: Re: [Caml-list] restricting and hiding record fields for functors
Hello.

Maybe private row types are useful to you;
see the Language extensions section of the OCaml manual:
http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html

You can do something like this:

  module M = struct
    type t = < x:int; y:int>
    let r = object method x = 1 method y = 2 end
  end;;
  
  module F(X:sig type t = private <x:int; ..> val r: t end) = 
    struct  let x = X.r#x  end;;
  
  module FM = F(M);;
  let x = FM.x;;


I often prefer to use a syntax extension,
found at http://www.math.nagoya-u.ac.jp/~garrigue/code/ocaml.html,
which allows me to write

  let r = {| x = 1 method y = 2 |}

instead of 

  let r = object method x = 1 method y = 2 end


With best regards,
Keiko