aboutsummaryrefslogtreecommitdiff
path: root/src/scTypes.mli
blob: 326a31c07f25b1b58e3a2d1cdaac4846b0339062 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
(*
This file is part of licht.

licht is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

licht is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with licht.  If not, see <http://www.gnu.org/licenses/>.
*)

(** All the types used in the spreadsheet. *)

(** This module describe the most basic type use in the spreadsheet : every content is,

- either a ['a t]
- either an expression which result to one ['a t]

*)
module Type : sig

  type 'a t

  (** Create a new number *)
  val number: DataType.Num.t -> DataType.Num.t t

  (** Create a new string *)
  val string: DataType.String.t -> DataType.String.t t

  (** Create a new boolean *)
  val boolean: DataType.Bool.t -> DataType.Bool.t t

  (** Create a new date *)
  val date: DataType.Num.t -> DataType.Num.t t

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

  (** Evaluate a type and get the result *)
  module Eval(T:Sym_type.SYM_TYPE): sig

    val eval: 'a t -> 'a T.obs

  end

end

(** A reference to another cell.

The reference can be a single cell (ie : A$1) or a range.

*)
module Refs : sig

  type t 

  val cell : Cell.t -> t

  val range : Cell.t -> Cell.t -> t

  (** Evaluate a reference and get the result *)
  module Eval(R:Sym_ref.SYM_REF): sig

    val eval: t -> 'a R.obs

  end

end

module Expr : sig

  type ident = UTF8.t

  (** This is the cell content *)
  type t

  (** Declare a direct value *)
  val value: 'a Type.t -> t

  (** Declare a reference to another cell *)
  val ref: Refs.t -> t

  (** Declare a call to a 0 arg function *)
  val call0: ident -> t

  (** Declare a call to a 1 arg function *)
  val call1 : ident -> t -> t

  (** Declare a call to a 2 arg function *)
  val call2 : ident -> t -> t -> t

  (** Declare a call to a 3 arg function *)
  val call3 : ident -> t -> t -> t -> t

  (** Declare a call to a function *)
  val callN : ident -> t list -> t

  (** An expression *)
  val expression : t -> t

  module Eval(E:Sym_expr.SYM_EXPR): sig

    val eval: t -> E.obs

  end

end

module DataFormat : sig

  type 'a t =
    | Date: DataType.Num.t t      (* A date in julian day *)
    | Number: DataType.Num.t t    (* Number *)
    | String: DataType.String.t t (* String *)
    | Bool: DataType.Bool.t t     (* Boolean *)
  
  type formats = F : 'a t -> formats [@@unboxed]

  val default_value_for: 'a t -> 'a

  type ('a, 'b) equality = Eq : ('a, 'a) equality

  val compare_format: 'a t -> 'b t -> ('a, 'b) equality

  val priority: 'a t -> int

end

module ReturnType : sig

  (** Private type for an internal representation of return format *)
  type 'a t
  
  (** Numeric (any format) *)
  val f_num: DataType.Num.t t
  
  (** Date *)
  val f_date: DataType.Num.t t
  
  (** Number *)
  val f_number: DataType.Num.t t
  
  (** Boolean result *)
  val f_bool: DataType.Bool.t t
  
  (** String *)
  val f_string: DataType.String.t t

  val guess_format_result: 'a t -> (unit -> DataFormat.formats list) -> 'a DataFormat.t

end

module Result : sig

  (** Result from a computation *)
  type t =
    | Ok : 'a Type.t -> t
    | Error : exn -> t

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

  val show: t -> UTF8.t

end

exception Error