Anonymous avatar Anonymous committed 9bc3cd9

Submit cf-0.1 release.

Comments (0)

Files changed (4)

 (*---------------------------------------------------------------------------*
   IMPLEMENTATION  cf_seq.ml
 
-  Copyright (c) 2002, James H. Woodyatt
+  Copyright (c) 2002-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
     | Z ->
         ()
 
+let finishC_ _ = Lazy.lazy_from_val Z
+let finishSC_ _ _ = Lazy.lazy_from_val Z
+
+let writeC o f = lazy (P (o, f ()))
+let evalC m = m finishC_
+
+let writeSC o f s = lazy (P (o, f () s))
+let evalSC m s = m finishSC_ s
+
+module S = struct
+    open Cf_smonad
+    open Op
+    
+    let accumulate =
+        let rec loop stack seq =
+            match Lazy.force seq with
+            | P (hd, tl) -> hd >>= fun x -> loop (x :: stack) tl
+            | Z -> return (List.rev stack)
+        in
+        fun s -> loop [] s
+
+    let rec sequence s =
+        match Lazy.force s with
+        | P (hd, tl) -> hd >>= fun _ -> sequence tl
+        | Z -> return ()
+end
+
+module C = struct
+    open Cf_cmonad
+    open Op
+    
+    let accumulate =
+        let rec loop stack seq =
+            match Lazy.force seq with
+            | P (hd, tl) -> hd >>= fun x -> loop (x :: stack) tl
+            | Z -> return (List.rev stack)
+        in
+        fun s -> loop [] s
+
+    let rec sequence s =
+        match Lazy.force s with
+        | P (hd, tl) -> hd >>= fun _ -> sequence tl
+        | Z -> return ()
+end
+
+module SC = struct
+    open Cf_scmonad
+    open Op
+    
+    let accumulate =
+        let rec loop stack seq =
+            match Lazy.force seq with
+            | P (hd, tl) -> hd >>= fun x -> loop (x :: stack) tl
+            | Z -> return (List.rev stack)
+        in
+        fun s -> loop [] s
+
+    let rec sequence s =
+        match Lazy.force s with
+        | P (hd, tl) -> hd >>= fun _ -> sequence tl
+        | Z -> return ()
+end
+
 (*--- Snd of File [ cf_seq.ml ] ---*)
 (*---------------------------------------------------------------------------*
   INTERFACE  cf_seq.mli
 
-  Copyright (c) 2002, James H. Woodyatt
+  Copyright (c) 2002-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
 *)
 val to_buffer: char t -> Buffer.t -> unit
 
+(** {6 Monad Functions} *)
+
+(** Use [write x] to compose a continuation monad that puts [x] into the
+    sequence produced by evaluation and returns the unit value.
+*)
+val writeC: 'x -> ('x t, unit) Cf_cmonad.t
+
+(** Use [evalC m] to evaluate the continuation monad [m] to compute the
+    sequence it encapsulates.
+*)
+val evalC: ('x t, unit) Cf_cmonad.t -> 'x t
+
+(** Use [writeSC x] to compose a state-continuation monad that puts [x] into
+    the sequence produced by evaluation and returns the unit value.
+*)
+val writeSC: 'x -> ('s, 'x t, unit) Cf_scmonad.t
+
+(** Use [evalSC m s] to evaluate the state-continuation monad [m] with the
+    initial state [s], computing the encapsulated sequence.
+*)
+val evalSC: ('s, 'x t, unit) Cf_scmonad.t -> 's -> 'x t
+
+(** The module containing the [sequence] and [accumulate] functions for the
+    state monad.
+*)
+module S: sig
+
+    (** Use [sequence z] to compose a monad that binds all of the monads in the
+        sequence [z] in the order specified.  Returns the unit value.
+    *)
+    val sequence: ('x, unit) Cf_smonad.t t -> ('x, unit) Cf_smonad.t
+    
+    (** Use [accumulate z] to compose a monad that binds all of the monads in
+        the sequence [z] in the order specified, accumulating all of the values
+        returned into a list.
+    *)
+    val accumulate: ('x, 'a) Cf_smonad.t t -> ('x, 'a list) Cf_smonad.t
+end
+
+(** The module containing the [sequence] and [accumulate] functions for the
+    continuation monad.
+*)
+module C: sig
+
+    (** Use [sequence z] to compose a monad that binds all of the monads in the
+        sequence [z] in the order specified.  Returns the unit value.
+    *)
+    val sequence: ('x, unit) Cf_cmonad.t t -> ('x, unit) Cf_cmonad.t
+    
+    (** Use [accumulate z] to compose a monad that binds all of the monads in
+        the sequence [z] in the order specified, accumulating all of the values
+        returned into a list.
+    *)
+    val accumulate: ('x, 'a) Cf_cmonad.t t -> ('x, 'a list) Cf_cmonad.t
+end
+
+(** The module containing the [sequence] and [accumulate] functions for the
+    state-continuation monad.
+*)
+module SC: sig
+
+    (** Use [sequence z] to compose a monad that binds all of the monads in the
+        sequence [z] in the order specified.  Returns the unit value.
+    *)
+    val sequence: ('s, 'x, unit) Cf_scmonad.t t -> ('s, 'x, unit) Cf_scmonad.t
+    
+    (** Use [accumulate z] to compose a monad that binds all of the monads in
+        the sequence [z] in the order specified, accumulating all of the values
+        returned into a list.
+    *)
+    val accumulate:
+        ('s, 'x, 'a) Cf_scmonad.t t -> ('s, 'x, 'a list) Cf_scmonad.t
+end
+
 (*--- End of File [ cf_seq.mli ] ---*)
 (*---------------------------------------------------------------------------*
   IMPLEMENTATION  cf_set.ml
 
-  Copyright (c) 2002, James H. Woodyatt
+  Copyright (c) 2002-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
 (*---------------------------------------------------------------------------*
   INTERFACE  cf_set.mli
 
-  Copyright (c) 2002, James H. Woodyatt
+  Copyright (c) 2002-2004, James H. Woodyatt
   All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.