diff options
Diffstat (limited to 'src/expressions/collect_sources.ml')
| -rwxr-xr-x | src/expressions/collect_sources.ml | 69 | 
1 files changed, 69 insertions, 0 deletions
diff --git a/src/expressions/collect_sources.ml b/src/expressions/collect_sources.ml new file mode 100755 index 0000000..d898b86 --- /dev/null +++ b/src/expressions/collect_sources.ml @@ -0,0 +1,69 @@ +module T = struct
 +
 +  type 'a t = unit
 +
 +  type 'a obs = ('a -> 'a)
 +
 +  let str s = ()
 +
 +  let num n = ()
 +
 +  let date d = ()
 +
 +  let bool b = ()
 +
 +  let observe () x = x
 +
 +end
 +
 +module R = struct
 +
 +  type 'a obs = Cell.Set.t -> Cell.Set.t
 +
 +  type 'a t = 'a obs
 +
 +  let cell (c:Cell.t) set = Cell.Set.add (Cell.to_pair c) set
 +
 +  let range c1 c2 set = begin
 +
 +    let x1, y1 = Cell.to_pair c1
 +    and x2, y2 = Cell.to_pair c2 in
 +
 +    let f_x x acc = begin
 +      let f_y y acc = begin
 +        Cell.Set.add (x, y) acc
 +      end in
 +      Tools.fold_for f_y y1 y2 acc
 +    end in
 +    Tools.fold_for f_x x1 x2 set
 +  end
 +
 +  let observe elem set = elem set
 +
 +
 +end
 +
 +let observe f value = f value
 +
 +let value v () = T.observe v
 +
 +let ref r () = R.observe r
 +
 +let call0 ident () acc = acc
 +
 +let call1 ident p1 () acc = observe p1 acc
 +
 +let call2 ident p1 p2 () acc = observe p2 (observe p1 acc)
 +
 +let call3 ident p1 p2 p3 () acc = observe p3 (observe p2 (observe p1 acc))
 +
 +let callN ident params () acc = List.fold_left (fun acc p -> observe p acc) acc params
 +
 +let expression e () = e
 +
 +type obs =  Cell.Set.t -> Cell.Set.t
 +
 +type t = unit
 +
 +type repr = obs
 +
  | 
