Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* reactive.ml *)
- module Declarative = struct
- module Map = Hmap
- type ex_index = Map.Key.t
- type _ type_ =
- | T_String : string type_
- | T_Tuple_2 : ('a type_ * 'b type_) -> ('a * 'b) type_
- type _ constructor =
- | C_String : string -> string constructor
- | C_Tuple_2 : ('a constructor * 'b constructor) -> ('a * 'b) constructor
- type _ reactive =
- | R_String : string Variable.t -> string reactive
- | R_Tuple_2 : (('a , 'b) Tuple_2.t * 'a reactive * 'b reactive) -> ('a * 'b) reactive
- let get_var : type a . a reactive -> a Variable.t = function
- | R_String x -> x
- | R_Tuple_2 (tpl , _ , _) -> (
- let updater_forth (a , b) = (a , b) in
- let updater_back (a , b) = (a , b) in
- Tuple_2.map_from ~updater_forth ~updater_back tpl
- )
- let rec make : type a . a constructor -> a reactive = function
- | C_String str -> (
- let v = Variable.make str in
- R_String v
- )
- | C_Tuple_2 (a , b) -> (
- let a' = make a in
- let b' = make b in
- let tpl = Tuple_2.make ~bidirectional:true (get_var a' , get_var b') in
- R_Tuple_2 (tpl , a' , b')
- )
- end
- (* main.ml *)
- let () =
- let (R_Tuple_2 (fullName , R_String firstName , R_String lastName)) = R.Declarative.make @@ C_Tuple_2 (C_String "Will" , C_String "Smith") in
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement