Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / CoolUtils.mli @ 1d36cd07

History | View | Annotate | Download (2.71 KB)

1

    
2
(** Some basic utilities as they are known from haskell prelude and so on... *)
3

    
4
(** Additional utility functions for the Array module  *)
5
module TArray : sig
6
    val all : ('a -> bool) -> 'a array -> bool
7
    val any : ('a -> bool) -> 'a array -> bool
8
    val elem : 'a -> 'a array -> bool
9
    val included : 'a array -> 'a array -> bool
10
    val to_string : ('a -> string) -> 'a array -> string
11
    val uniq : 'a array -> 'a array (** delete consecutive duplicates *)
12
end
13

    
14
(** Additional utility functions for the List module  *)
15
module TList : sig
16
    val zip : ('a list) -> ('b list) -> ('a * 'b) list
17
    val powerset : ('a list) -> ('a list list)
18
    val prod : ('a list) -> ('b list) -> (('a * 'b) list)
19
    val empty : ('a list) -> bool
20

    
21
    (** Compute possible combinations of the sublists.
22

    
23
        [combinations [[1;2];[3;4]] = [[1;3];[1;4];[2;3];[2;4]]]
24
     *)
25
    val combinations : 'a list list -> 'a list list
26
end
27

    
28
(** Command line argument parser *)
29
module Args : sig
30
  type 'a param_parser = 'a -> 'a
31

    
32
  (** Specifies whether the option takes an addition paramter. *)
33
  type 'a argument = Required_arg of string * (string -> 'a param_parser)
34
                     (** name of the argument and parser. 
35
                         Parser can throw ParseErrors
36
                      *)
37
                   | No_arg of 'a param_parser
38

    
39
  type 'a description =
40
    { long : string
41
    ; short : char option
42
    ; description : string
43
    ; argument : 'a argument
44
    }
45

    
46
  exception ParseError of string
47

    
48
  type 'a result = Ok of 'a | Error of string
49

    
50
  (** parses command line options.
51

    
52
      The user can choose the type 'a, provided they provide parsers and a
53
      default value.
54

    
55
      @param argv The Sys.argv array
56
      @param offset The index in [argv] where option parsing should start
57
      @param options Descriptions of all available options
58
      @param default Default value for the option type
59
      @return The option type or a parse error
60
   *)
61
  val parse : argv:string array -> offset:int -> options:'a description list
62
              -> default:'a -> 'a result
63

    
64
  (** [help out indent options] prints help for [options] to [out] indented
65
      by [indent] characters *)
66
  val help : out_channel -> int -> 'a description list -> unit
67
end
68

    
69
val cl_get_agents : unit -> int array
70
val cl_set_agents : int array -> unit
71

    
72
val intlist_of_string : string -> int list
73

    
74
val compose : ('b -> 'c) -> ('a -> 'b) -> ('a -> 'c)
75
val flip : ('a -> 'b -> 'c) -> ('b -> 'a -> 'c)
76
val eval : 'a -> ('a -> 'b) -> 'b
77
val id : 'a -> 'a
78
val foreach_l : ('a list) -> ('a -> unit) -> unit
79
val repeat : int -> (unit -> unit) -> unit
80
val (<<) : ('b -> 'c) -> ('a -> 'b) -> ('a -> 'c)
81

    
82
exception No_value
83
val fromSome : 'a option -> 'a
84

    
85

    
86
(* vim: set et sw=2 sts=2 ts=8 : *)