Skip to content

Commit b374111

Browse files
committed
Cleaning
1 parent d7e9ad3 commit b374111

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

ML/Util.sml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
structure Util =
22
struct
33

4-
(*** Printing utilites ***)
4+
(** Printing utilites **)
55
fun println s = print (s ^ "\n")
66

77
fun list_to_string f = (fn x => "[" ^ x ^ "]") o String.concatWith ", " o map f
@@ -10,6 +10,7 @@ fun print_result NONE = println("Invalid input\n")
1010
| print_result (SOME true) = println("Property is satisfied\n")
1111
| print_result (SOME false) = println("Property is not satisfied\n")
1212

13+
(** File reading **)
1314
fun read_lines stream =
1415
let
1516
val input = TextIO.inputLine stream
@@ -20,16 +21,33 @@ fun read_lines stream =
2021
| SOME input => input ^ read_lines stream
2122
end
2223

23-
fun find_with_arg P [] = NONE
24-
| find_with_arg P [_] = NONE
25-
| find_with_arg P (x :: y :: xs) = if P x then SOME y else find_with_arg P (y :: xs)
24+
fun read_file f =
25+
let
26+
val file = TextIO.openIn f
27+
val s = read_lines file
28+
val _ = TextIO.closeIn file
29+
in s end
2630

31+
(** Processing command line arguments **)
2732
datatype 'a argument = Is_Present | Is_Not_Present | Has_Val of 'a
2833

2934
type arguments = string argument list
3035

3136
exception Unknown_Argument of string
3237

38+
datatype argument_type = Arg | Flag
39+
40+
val common_arguments = [
41+
(["deadlock", "dc"], "Ignore formula and run deadlock check.", Flag),
42+
(["model", "m"],
43+
"Input file for the model & formula. "
44+
^ "If this is not specified, the input is read from stdin.",
45+
Arg),
46+
(["help", "h", "?"], "Show this help string.", Flag),
47+
(["cpu-time", "cpu"], "Report CPU time.", Flag),
48+
(["num-threads", "n"], "Number of threads.", Arg)
49+
]
50+
3351
val the_args = ref []
3452

3553
fun is_present arg = case List.find (fn (k, v) => k = arg) (!the_args) of
@@ -44,18 +62,9 @@ fun find_arg arg = case List.find (fn (k, v) => k = arg) (!the_args) of
4462

4563
val get_arg = the o find_arg
4664

47-
datatype argument_type = Arg | Flag
48-
49-
val common_arguments = [
50-
(["deadlock", "dc"], "Ignore formula and run deadlock check.", Flag),
51-
(["model", "m"],
52-
"Input file for the model & formula. "
53-
^ "If this is not specified, the input is read from stdin.",
54-
Arg),
55-
(["help", "h", "?"], "Show this help string.", Flag),
56-
(["cpu-time", "cpu"], "Report CPU time.", Flag),
57-
(["num-threads", "n"], "Number of threads.", Arg)
58-
]
65+
fun find_with_arg P [] = NONE
66+
| find_with_arg P [_] = NONE
67+
| find_with_arg P (x :: y :: xs) = if P x then SOME y else find_with_arg P (y :: xs)
5968

6069
fun read_arguments arguments =
6170
let
@@ -82,11 +91,4 @@ fun print_usage arguments =
8291
|> (fn s => "Usage:\n" ^ s)
8392
|> println
8493

85-
fun read_file f =
86-
let
87-
val file = TextIO.openIn f
88-
val s = read_lines file
89-
val _ = TextIO.closeIn file
90-
in s end
91-
9294
end

0 commit comments

Comments
 (0)