-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.sig
64 lines (44 loc) · 1.75 KB
/
util.sig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(* Copyright 2018, Martin Elsman, MIT-license *)
(** Utility library for general purpose small useful function. *)
signature UTIL = sig
(* Functional utilities *)
val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c
val uncurry : ('a -> 'b -> 'c) -> ('a * 'b) -> 'c
val $ : ('a -> 'b) * 'a -> 'b
(* Iteration *)
val iter : (int*'a -> 'a) -> 'a -> int*int -> 'a
(* Association lists *)
type (''a,'b) alist = (''a * 'b) list
val emptyAlist : unit -> (''a,'b) alist
val extendAlist : (''a,'b) alist -> ''a * 'b -> (''a,'b) alist
val lookupAlist : (''a,'b) alist -> ''a -> 'b option
val plusAlist : (''a,'b) alist * (''a,'b) alist -> (''a,'b) alist
val listContains : ''a -> ''a list -> bool
(* Printing *)
val intToCString : Int32.int -> string
val realToCString : real -> string
val realToTailString : real -> string
val quote : string -> string
val prln : string -> unit
val log : bool -> (unit -> string) -> unit
(* Minimum and maximum values *)
val minInt : Int32.int
val maxInt : Int32.int
(* File manipulation *)
val readFile : string -> string
end
(**
[curry f a b] returns f(a,b).
[uncurry f (a,b)] returns f a b.
[f $ a] returns f a. Useful when the right-hand-side is a complex
expression.
[iter f a (i,j)] returns the result of accumulating the result of
applying f over the interval [i;j]. Identical to
f(j,...f(i+1,f(i,a))...) if i <= j. Returns a if i > j.
[intToCString i] returns a C syntactic string representation of the
integer i (as a C int).
[realToCString r] returns a C syntactic string representation of the
real r (as a C double).
[readfile f] returns the content of the file s. Raises an exception if
the file does not exists or cannot be opened for reading.
*)