aboutsummaryrefslogtreecommitdiff
path: root/src/scTypes.mli
blob: f7bcc1b8c983c81c0967dae13bd693b8a7ce46ce (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
(** 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

  val shift: (int * int) -> 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

  val shift_exp: (int * int) -> t -> t

  module Eval(E:Sym_expr.SYM_EXPR): sig

    val eval: t -> E.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