Commits

Anonymous committed 66a2305

Change [null] to a monad, and add [connect] and [connectpair] primitives.

Comments (0)

Files changed (4)

 Highlights of the changes:
 
 + Compatibility with FreeBSD 6.2.
++ Compatibility with OCaml-3.10.0
++ Deprecated all the network extension modules, which are now delivered in the
+  Nx library.  If you still need them Cf versions, you can restore them by a
+  simple edit of the Makefile.
++ Changed type of [Cf_gadget.null] to a monad.  Added some additional monads.
 
+--- [Cf_gadget]
+    The [null] object is now a monad that producs a null wire.  New [connect]
+    and [connectpair] functions are generalizations of the [simplex] and
+    [duplex] functions.
+    
 
 ===== Version 0.9 =====
 
 # The following META file is a guess by ocamlfind:
 name="cf"
-version="0.10"
+version="0.11"
 description="OCaml NAE Core Foundation"
 requires="unix"
 archive(byte)="cf.cma"
     | L_pending of ('i, 'o) gates
     | L_discard
 
-
 let rec scheduler_ Void =
     Cf_scmonad.load >>= fun k ->
     let m, gQ, rQ = guardLoop_ k.msgQM k.guardQ Cf_deque.nil Cf_deque.nil in
 let wire c = wireAux_ c
 let wirepair c = wirepairAux_ c
 
-let null =
-    let wref = Wire (0, Weak.create 1, Some "null") in
-    wref, wref
+let nullAux_ = Wire (0, Weak.create 1, Some "null")
+let null c = c (nullAux_, nullAux_)
 
 let read f =
     Cf_scmonad.modify begin fun k ->
     method put: 'x -> ('i, 'o, unit) t = fun x c -> txPut_ wref x c
 end
 
-let simplex c = wire (fun w -> c (new rx w, new tx w))
+let connect m c = m (fun w -> c (new rx w, new tx w))
+let simplex c = connect wire c
 
 type ('x, 'y, 'i, 'o) plug = ('x, 'i, 'o) rx * ('y, 'i, 'o) tx
 type ('x, 'y, 'i, 'o) jack = ('y, 'i, 'o) rx * ('x, 'i, 'o) tx
 
-let duplex c =
+let connectpair m c =
     let f (a, b) = c ((new rx a, new tx b), (new rx b, new tx a)) in
-    wirepair f
+    m f
+
+let duplex c = connectpair wirepair c
 
 let wrap x y =
     let x = (x :> ('x, 'i, 'o) rx) in
 *)
 val wirepair: ('i, 'o, ('x, 'i, 'o) wire * ('y, 'i, 'o) wire) t
 
-(** Use [null] to construct a [rx] object that produces gates that never
-    receive any messages, and a [tx] object that discards every message
-    transmitted without deliver it.  This object can be useful for default
-    arguments to some gadget functions.
+(** Use [null] to construct a wire that discards every message transmitted
+    without ever delivering it.  Such wires can be useful for default arguments
+    to some gadget functions.
 *)
-val null: ('x, 'i, 'o) wire
+val null: ('i, 'o, ('x, 'i, 'o) wire) t
 
 (** Bind [read] to get the next input value from the external stream. *)
 val read: ('i, 'o, 'i) t
 
 (** {6 Miscellaneous} *)
 
-(** Use [simplex] to construct a new maching pair of [rx] and [tx] objects.*)
+(** Use [connect m] to construct a new matching pair of [rx] and [tx] objects
+    from the wire returned by [m].
+*)
+val connect:
+    ('i, 'o, ('x, 'i, 'o) wire) t ->
+    ('i, 'o, ('x, 'i, 'o) rx * ('x, 'i, 'o) tx) t
+
+(** Use [simplex] to construct a new matching pair of [rx] and [tx] objects.
+    This is a convenient abbreviation of [connect wire].
+*)
 val simplex: ('i, 'o, ('x, 'i, 'o) rx * ('x, 'i, 'o) tx) t
 
 (** A pair of convenience types for representing each end of a bundle of two
 type ('x, 'y, 'i, 'o) plug = ('x, 'i, 'o) rx * ('y, 'i, 'o) tx
 type ('x, 'y, 'i, 'o) jack = ('y, 'i, 'o) rx * ('x, 'i, 'o) tx
 
+(** Use [connectpair m] to construct a new duplex communication channel,
+    composed with the wire pair returned by [m].  A matching jack and plug of
+    the channel are returned.
+*)
+val connectpair:
+    ('i, 'o, ('x, 'i, 'o) wire * ('y, 'i, 'o) wire) t ->
+    ('i, 'o, ('x, 'y, 'i, 'o) jack * ('x, 'y, 'i, 'o) plug) t
+
 (** Use [duplex] to construct a new duplex communication channel, composed of
     two wires each in opposite flow.  A matching jack and plug of the channel
-    is returned.
+    are returned.  This is a convenient abbreviation of [connectpair wirepair].
 *)
 val duplex: ('i, 'o, ('x, 'y, 'i, 'o) jack * ('x, 'y, 'i, 'o) plug) t