Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type (_, _) term =
- | Int: (int -> 'a, 'a) term
- | String: (string -> 'a, 'a) term
- | Const: string -> ('a, 'a) term
- type (_, _) term_list =
- | [] : ('a, 'a) term_list
- | (::) : ('a, 'b) term * ('b, 'c) term_list -> ('a, 'c) term_list
- (* Construct a function that takes same arguments and produces a string *)
- let rec encoder: type b. (b, string) term_list -> string -> b = function
- | Int :: xs ->
- fun acc v -> encoder xs (Printf.sprintf "%s %d" acc v)
- | String :: xs ->
- fun acc v -> encoder xs (Printf.sprintf "%s '%s'" acc v)
- | Const s :: xs ->
- fun acc -> encoder xs (Printf.sprintf "%s %s" acc s)
- | [] -> fun x -> x
- let expr = Const "SELECT a FROM x WHERE a =" :: Int :: Const "AND x.y =" :: String :: Const "ORDER BY a" :: []
- let expr_func = encoder expr ""
- let () = Printf.printf "Result: %s\n" (expr_func 5 "value")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement