[MLton-user] Extended Basis Library: proposed sequence concept
Geoffrey Alan Washburn
geoffw at cis.upenn.edu
Tue Mar 20 05:50:21 PST 2007
I was starting on a »generic« zip/unzip library for
sequences,but realized that there was not any actual common
ancestry for the signatures in the sequence directory. I put
this together by distilling the commonality between lists,
arrays, and vectors. There actually could be more
commonality between them; I noticed at least the following
discrepancies:
- List does not have »extract«.
- List's »mapi«/»appi«/etc. are different in form than
those in Array and Vector.
- Array does not have »concat«, though I would agree that
whether it should is debatable.
- List does not have »fromList« and »toList«. While
trivial, these would add further uniformity.
- Array and Vector could possibly support a number of
list-like operations that they currently don't:
»hd«, »tl«, »rev«, etc.
Index: sequence.sig
===================================================================
--- sequence.sig (revision 0)
+++ sequence.sig (revision 0)
@@ -0,0 +1,43 @@
+(* Copyright (C) 2007 ????
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(** == Sequences ==
+ *
+ * Sequence types are polymorphic containers that has a linear
+ * ordering on its elements. Sequences do not need to be
+ * finite, but some additional operations are available for
+ * sequences those that are known to be finite or infinite
+ * respectively.
+ *)
+
+(** === All sequences == *)
+
+signature SEQUENCE_CORE = sig
+ type 'a seq
+ val sub : 'a seq * Int.t -> 'a
+ val map : ('a -> 'b) -> 'a seq -> 'b seq
+ val app : 'a Effect.t -> 'a seq Effect.t
+ val foldr : ('a * 'b -> 'b) -> 'b -> 'a seq -> 'b
+end
+
+(** === Finite sequences == *)
+
+signature SEQUENCE_FINITE = sig
+ type 'a seq_fin
+ val empty : 'a seq_fin
+ val length : 'a seq_fin -> Int.t
+ val foldl : ('a * 'b -> 'b) -> 'b -> 'a seq_fin -> 'b
+ val tabulate : (Int.t * (Int.t -> 'a)) -> 'a seq_fin
+end
+
+(** === Infinite sequences == *)
+
+signature SEQUENCE_INFINITE = sig
+ type 'a seq_inf
+
+ val iteratei : (Int.t * 'a -> 'a) -> 'a seq_inf
+ val iterate : ('a -> 'a) -> 'a seq_inf
+end
+
Property changes on: sequence.sig
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the MLton-user
mailing list