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

SCM Repository

[smlnj] Diff of /sml/trunk/src/compiler/FLINT/opt/optutils.sml
ViewVC logotype

Diff of /sml/trunk/src/compiler/FLINT/opt/optutils.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 199, Wed Nov 25 18:30:38 1998 UTC revision 203, Sat Dec 19 20:51:39 1998 UTC
# Line 12  Line 12 
12                        (FLINT.fkind * FLINT.fkind)                        (FLINT.fkind * FLINT.fkind)
13    
14      (* this is a known APL function, but I don't know its real name *)      (* this is a known APL function, but I don't know its real name *)
15      val filter : bool list * 'a list -> 'a list      val filter : bool list -> 'a list -> 'a list
16    
17      (* A less brain-dead version of ListPair.all: returns false if      (* A less brain-dead version of ListPair.all: returns false if
18       * length l1 <> length l2 *)       * length l1 <> length l2 *)
19      val ListPair_all : ('a * 'b -> bool) -> 'a list * 'b list -> bool      val ListPair_all : ('a * 'b -> bool) -> 'a list * 'b list -> bool
20    
21        val pow2 : int -> int
22    
23        (* This is not a proper transposition in that the order is reversed
24         * in the following way:  transpose x = map rev (proper_trans x) *)
25        exception Unbalanced
26        val transpose : 'a list list -> 'a list list
27    
28        val foldl3 : ('a * 'b * 'c * 'd -> 'd) -> 'd -> 'a list * 'b list * 'c list -> 'd
29  end  end
30    
31  structure OptUtils :> OPT_UTILS =  structure OptUtils :> OPT_UTILS =
# Line 38  Line 47 
47              {isrec=isrec', known=true, cconv=cconv', inline=inline})              {isrec=isrec', known=true, cconv=cconv', inline=inline})
48          end          end
49    
50      fun filter ([],[]) = []      fun filter [] [] = []
51        | filter (true::fs,x::xs)  = x::(filter(fs, xs))        | filter (true::fs) (x::xs)  = x::(filter fs xs)
52        | filter (false::fs,x::xs) = (filter(fs, xs))        | filter (false::fs) (x::xs) = (filter fs xs)
53        | filter _ = bug "unmatched list length in filter"        | filter _ _ = bug "unmatched list length in filter"
54    
55      fun ListPair_all pred =      fun ListPair_all pred =
56          let fun allp (a::r1, b::r2) = pred(a, b) andalso allp (r1, r2)          let fun allp (a::r1, b::r2) = pred(a, b) andalso allp (r1, r2)
# Line 50  Line 59 
59          in allp          in allp
60          end          end
61    
62        fun pow2 n = Word.toInt(Word.<<(Word.fromInt 1, Word.fromInt n))
63    
64        exception Unbalanced
65        fun transpose [] = []
66          | transpose (xs::xss) =
67            let fun tr [] accs = accs
68                  | tr (xs::xss) accs =
69                    let fun f [] [] = []
70                          | f (x::xs) (acc::accs) = (x::acc)::(f xs accs)
71                          | f _ _ = raise Unbalanced
72                    in tr xss (f xs accs)
73                    end
74            in tr xss (map (fn x => [x]) xs)
75            end
76    
77        fun foldl3 f =
78            let fun l s ([],[],[]) = s
79                  | l s (x1::x1s,x2::x2s,x3::x3s) = l (f(x1,x2,x3,s)) (x1s,x2s,x3s)
80                  | l _ _ = raise Unbalanced
81            in l
82            end
83    
84  end  end
85  end  end

Legend:
Removed from v.199  
changed lines
  Added in v.203

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