Browse thread
Record field label locality
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Richard Jones <rich@a...> |
| Subject: | Re: [Caml-list] Record field label locality |
On Tue, Aug 12, 2008 at 02:03:46PM -0700, Brighten Godfrey wrote: > I think I see what you're getting at. Is it possible to define > compositionality as follows?: I think Jon means that you can copy and paste code around and it still works. > "Removing a type annotation from > correct OCaml code results in correct OCaml code." This is mostly correct. However very occasionally it is necessary to help the compiler out by annotating expressions with types. I believe this is because type inference used by OCaml is undecidable. You'll notice this effect more often if you use OCaml's object system. > I would claim that the current syntax (`g.Graph.nodes' in the above > example) is effectively a type annotation that permits the type > inference that `g' is a `Graph.t'. The annoying bit is that you are > required to use every single time you use a record in `g'. You might want to try renaming the Graph module, ie: module G = Graph ... g.G.nodes ... Or if you have control over the module itself, you could also try renaming the fields to make them unique (eg. g_nodes), at which point you can just 'open Graph'. There are different trade-offs to each approach. Rich. -- Richard Jones Red Hat