Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /smlnj-lib/trunk/Util/list-xprod.sml
ViewVC logotype

Annotation of /smlnj-lib/trunk/Util/list-xprod.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)
Original Path: sml/trunk/src/smlnj-lib/Util/list-xprod.sml

1 : monnier 2 (* list-xprod.sml
2 :     *
3 :     * COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details.
4 :     *
5 :     * Functions for computing with the cross product of two lists.
6 :     *)
7 :    
8 :     structure ListXProd : LIST_XPROD =
9 :     struct
10 :    
11 :     (* apply a function to the cross product of two lists *)
12 :     fun appX f (l1, l2) = let
13 :     fun lp1 [] = ()
14 :     | lp1 (x::r) = let
15 :     fun lp2 [] = lp1 r
16 :     | lp2 (y::r) = (f(x, y); lp2 r)
17 :     in
18 :     lp2 l2
19 :     end
20 :     in
21 :     lp1 l1
22 :     end
23 :    
24 :     (* map a function across the cross product of two lists *)
25 :     fun mapX f (l1, l2) = let
26 :     fun lp1 ([], resL) = rev resL
27 :     | lp1 (x::r, resL) = let
28 :     fun lp2 ([], resL) = lp1 (r, resL)
29 :     | lp2 (y::r, resL) = lp2 (r, f(x, y) :: resL)
30 :     in
31 :     lp2 (l2, resL)
32 :     end
33 :     in
34 :     lp1 (l1, [])
35 :     end
36 :    
37 :     (* fold a function across the cross product of two lists *)
38 :     fun foldX f (l1, l2) = let
39 :     fun lp1 ([], accum) = accum
40 :     | lp1 (x::r, accum) = let
41 :     fun lp2 ([], accum) = lp1 (r, accum)
42 :     | lp2 (y::r, accum) = lp2 (r, f(x, y, accum))
43 :     in
44 :     lp2 (l2, accum)
45 :     end
46 :     in
47 :     fn init => lp1 (l1, init)
48 :     end
49 :    
50 :     end; (* ListXProd *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0