aboutsummaryrefslogtreecommitdiff
path: root/scTypes.mli
blob: de0d6f26a2dae445e2cb38bab89ca8f0f145aed0 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(** All the types used in the spreadsheet. *)

exception Error

type cell = (int * int) * (bool * bool)

type ident = UTF8.t

type 'a dataFormat =
  | Date: DataType.Num.t dataFormat    (* A date in julian day *)
  | Number: DataType.Num.t dataFormat  (* Number *)
  | String: DataType.String.t dataFormat (* String *)
  | Bool: DataType.Bool.t dataFormat   (* Boolean *)

type 'a returnType =
  | Num  : DataType.Num.t dataFormat option -> DataType.Num.t returnType    (** A number *)
  | Str  : DataType.String.t returnType                         (** A string *)
  | Bool : DataType.Bool.t returnType                           (** A boolean *)

type numericType =
  | Date
  | Number

val get_numeric_type: DataType.Num.t dataFormat -> numericType

type 'a types = private
  | Num  : DataType.Num.t dataFormat * DataType.Num.t -> DataType.Num.t types    (** A number *)
  | Str  : DataType.String.t -> DataType.String.t types         (** A string *)
  | Bool : DataType.Bool.t -> DataType.Bool.t types             (** A boolean *)

val number: DataType.Num.t -> DataType.Num.t types
val string: DataType.String.t -> DataType.String.t types
val boolean: DataType.Bool.t -> DataType.Bool.t types
val date: DataType.Num.t -> DataType.Num.t types


(** Numeric (any format) *)
val f_num: DataType.Num.t returnType

(** Date *)
val f_date: DataType.Num.t returnType

(** Number *)
val f_number: DataType.Num.t returnType

(** Boolean result *)
val f_bool: DataType.Bool.t returnType

(** String *)
val f_string: DataType.String.t returnType

type refs =
  | Cell of cell                          (** A cell *)
  | Range of cell * cell                  (** An area of cells *)

(** This is the cell content *)
type expression =
  | Value : 'a types -> expression                    (** A direct value *)
  | Ref : refs -> expression                          (** A reference to another cell *)
  | Call : ident * expression list -> expression      (** A call to a function *)
  | Expression : expression -> expression             (** An expression *)

(** Result from a computation *)
type result =
  | Result : 'a types -> result
  | Error : exn -> result

module Type : sig

  type t = Value: 'a dataFormat * 'a -> t

  val (=) : 'a types -> 'b types -> bool

  val show: UTF8.Buffer.buffer -> 'a types -> unit

end

module Refs : sig

  type 'a range =
    | Single of 'a
    | Array1 of 'a list
    | Array2 of 'a list list

  val collect: refs -> (int * int) range

  val map: ('a -> 'b) -> 'a range -> 'b range
  
  val shift: (int * int) -> refs -> refs

  type 'a content =
    | Value: 'a dataFormat * 'a -> 'a content
    | List: 'a dataFormat * 'a list -> 'a list content
    | Matrix: 'a dataFormat * 'a list list -> 'a list list content

  type refContent =
    | C: 'a content -> refContent

  (** extract the content from a range.

      May raise Errors.TypeError if the range cannot be unified.
  *)
  val get_content : result option range -> refContent

end

val show_expr: UTF8.Buffer.buffer -> expression -> unit

module Result : sig

  val (=) : result -> result -> bool

  val show: result -> UTF8.t

end