equal
deleted
inserted
replaced
36 val tap: ('b -> 'a) -> 'b -> 'b |
36 val tap: ('b -> 'a) -> 'b -> 'b |
37 val oo: ('a -> 'b) * ('c -> 'd -> 'a) -> 'c -> 'd -> 'b |
37 val oo: ('a -> 'b) * ('c -> 'd -> 'a) -> 'c -> 'd -> 'b |
38 val ooo: ('a -> 'b) * ('c -> 'd -> 'e -> 'a) -> 'c -> 'd -> 'e -> 'b |
38 val ooo: ('a -> 'b) * ('c -> 'd -> 'e -> 'a) -> 'c -> 'd -> 'e -> 'b |
39 val oooo: ('a -> 'b) * ('c -> 'd -> 'e -> 'f -> 'a) -> 'c -> 'd -> 'e -> 'f -> 'b |
39 val oooo: ('a -> 'b) * ('c -> 'd -> 'e -> 'f -> 'a) -> 'c -> 'd -> 'e -> 'f -> 'b |
40 val funpow: int -> ('a -> 'a) -> 'a -> 'a |
40 val funpow: int -> ('a -> 'a) -> 'a -> 'a |
41 val apl: 'a * ('a * 'b -> 'c) -> 'b -> 'c |
|
42 val apr: ('a * 'b -> 'c) * 'b -> 'a -> 'c |
|
43 |
41 |
44 (*old options -- invalidated*) |
42 (*old options -- invalidated*) |
45 datatype invalid = None of invalid |
43 datatype invalid = None of invalid |
46 exception OPTION of invalid |
44 exception OPTION of invalid |
47 |
45 |
67 (*pairs*) |
65 (*pairs*) |
68 val pair: 'a -> 'b -> 'a * 'b |
66 val pair: 'a -> 'b -> 'a * 'b |
69 val rpair: 'a -> 'b -> 'b * 'a |
67 val rpair: 'a -> 'b -> 'b * 'a |
70 val fst: 'a * 'b -> 'a |
68 val fst: 'a * 'b -> 'a |
71 val snd: 'a * 'b -> 'b |
69 val snd: 'a * 'b -> 'b |
72 val eq_fst: (''a * 'b) * (''a * 'c) -> bool |
70 val eq_fst: ('a * 'c -> bool) -> ('a * 'b) * ('c * 'd) -> bool |
73 val eq_snd: ('a * ''b) * ('c * ''b) -> bool |
71 val eq_snd: ('b * 'd -> bool) -> ('a * 'b) * ('c * 'd) -> bool |
74 val swap: 'a * 'b -> 'b * 'a |
72 val swap: 'a * 'b -> 'b * 'a |
75 val apfst: ('a -> 'b) -> 'a * 'c -> 'b * 'c |
73 val apfst: ('a -> 'b) -> 'a * 'c -> 'b * 'c |
76 val apsnd: ('a -> 'b) -> 'c * 'a -> 'c * 'b |
74 val apsnd: ('a -> 'b) -> 'c * 'a -> 'c * 'b |
77 val pairself: ('a -> 'b) -> 'a * 'a -> 'b * 'b |
75 val pairself: ('a -> 'b) -> 'a * 'a -> 'b * 'b |
78 |
76 |
266 (*current directory*) |
264 (*current directory*) |
267 val cd: string -> unit |
265 val cd: string -> unit |
268 val pwd: unit -> string |
266 val pwd: unit -> string |
269 |
267 |
270 (*misc*) |
268 (*misc*) |
271 val make_keylist: ('a -> 'b) -> 'a list -> ('a * 'b) list |
|
272 val keyfilter: ('a * ''b) list -> ''b -> 'a list |
|
273 val partition_eq: ('a * 'a -> bool) -> 'a list -> 'a list list |
269 val partition_eq: ('a * 'a -> bool) -> 'a list -> 'a list list |
274 val partition_list: (int -> 'a -> bool) -> int -> int -> 'a list -> 'a list list |
270 val partition_list: (int -> 'a -> bool) -> int -> int -> 'a list -> 'a list list |
275 val gensym: string -> string |
271 val gensym: string -> string |
276 val scanwords: (string -> bool) -> string list -> string list |
272 val scanwords: (string -> bool) -> string list -> string list |
277 type stamp |
273 type stamp |
335 fun funpow n f x = |
331 fun funpow n f x = |
336 let fun rep (0, x) = x |
332 let fun rep (0, x) = x |
337 | rep (n, x) = rep (n - 1, f x) |
333 | rep (n, x) = rep (n - 1, f x) |
338 in rep (n, x) end; |
334 in rep (n, x) end; |
339 |
335 |
340 (*application of (infix) operator to its left or right argument*) |
|
341 fun apl (x, f) y = f (x, y); |
|
342 fun apr (f, y) x = f (x, y); |
|
343 |
|
344 |
336 |
345 (** options **) |
337 (** options **) |
346 |
338 |
347 (*invalidate former constructors to prevent accidental use as match-all patterns!*) |
339 (*invalidate former constructors to prevent accidental use as match-all patterns!*) |
348 datatype invalid = None of invalid; |
340 datatype invalid = None of invalid; |
405 fun rpair x y = (y, x); |
397 fun rpair x y = (y, x); |
406 |
398 |
407 fun fst (x, y) = x; |
399 fun fst (x, y) = x; |
408 fun snd (x, y) = y; |
400 fun snd (x, y) = y; |
409 |
401 |
410 fun eq_fst ((x1, _), (x2, _)) = x1 = x2; |
402 fun eq_fst eq ((x1, _), (x2, _)) = eq (x1, x2); |
411 fun eq_snd ((_, y1), (_, y2)) = y1 = y2; |
403 fun eq_snd eq ((_, y1), (_, y2)) = eq (y1, y2); |
412 |
404 |
413 fun swap (x, y) = (y, x); |
405 fun swap (x, y) = (y, x); |
414 |
406 |
415 (*apply function to components*) |
407 (*apply function to components*) |
416 fun apfst f (x, y) = (f x, y); |
408 fun apfst f (x, y) = (f x, y); |
1055 | gen_merge_lists' _ [] ys = ys |
1047 | gen_merge_lists' _ [] ys = ys |
1056 | gen_merge_lists' eq xs ys = gen_rems eq (ys, xs) @ xs; |
1048 | gen_merge_lists' eq xs ys = gen_rems eq (ys, xs) @ xs; |
1057 |
1049 |
1058 fun merge_lists xs ys = gen_merge_lists (op =) xs ys; |
1050 fun merge_lists xs ys = gen_merge_lists (op =) xs ys; |
1059 fun merge_lists' xs ys = gen_merge_lists' (op =) xs ys; |
1051 fun merge_lists' xs ys = gen_merge_lists' (op =) xs ys; |
1060 fun merge_alists al = gen_merge_lists eq_fst al; |
1052 fun merge_alists al = gen_merge_lists (eq_fst (op =)) al; |
1061 fun merge_alists' al = gen_merge_lists' eq_fst al; |
1053 fun merge_alists' al = gen_merge_lists' (eq_fst (op =)) al; |
1062 |
1054 |
1063 |
1055 |
1064 |
1056 |
1065 (** balanced trees **) |
1057 (** balanced trees **) |
1066 |
1058 |
1256 val rat0 = rat_of_int 0; |
1248 val rat0 = rat_of_int 0; |
1257 |
1249 |
1258 |
1250 |
1259 (** misc **) |
1251 (** misc **) |
1260 |
1252 |
1261 (*use the keyfun to make a list of (x, key) pairs*) |
|
1262 fun make_keylist (keyfun: 'a->'b) : 'a list -> ('a * 'b) list = |
|
1263 let fun keypair x = (x, keyfun x) |
|
1264 in map keypair end; |
|
1265 |
|
1266 (*given a list of (x, key) pairs and a searchkey |
|
1267 return the list of xs from each pair whose key equals searchkey*) |
|
1268 fun keyfilter [] searchkey = [] |
|
1269 | keyfilter ((x, key) :: pairs) searchkey = |
|
1270 if key = searchkey then x :: keyfilter pairs searchkey |
|
1271 else keyfilter pairs searchkey; |
|
1272 |
|
1273 |
|
1274 (*Partition list into elements that satisfy predicate and those that don't. |
1253 (*Partition list into elements that satisfy predicate and those that don't. |
1275 Preserves order of elements in both lists.*) |
1254 Preserves order of elements in both lists.*) |
1276 val partition = List.partition; |
1255 val partition = List.partition; |
1277 |
1256 |
1278 fun partition_eq (eq:'a * 'a -> bool) = |
1257 fun partition_eq (eq:'a * 'a -> bool) = |