Browse thread
Immutable cyclic data structures via a
[
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: | Jeremy Yallop <jeremy.yallop@e...> |
| Subject: | Re: [Caml-list] Immutable cyclic data structures via a |
Jeremy Yallop wrote:
> module Graph :
> sig
> module Mutable :
> sig
> type node = { mutable outgoing : edge list }
> and edge = { from : node ; to_ : node }
> end
>
> module Immutable :
> sig
> type node = private { mutable outgoing : edge list }
> and edge = { from : node ; to_ : node }
> end
>
> module Freeze :
> sig
> val node : Mutable.node -> Immutable.node
> val edge : Mutable.edge -> Immutable.edge
> end
> end =
I should also mention a drawback of this approach, which is that
"private" may be stronger than you need. Values of private record type
can be neither updated *nor created*; outside the Graph module you
cannot construct fresh values of Immutable.node, or even use "functional
update" (i.e. "with" syntax) to construct new values from existing
Immutable.node values.
Jeremy.
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.