Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module CharSet = Set.Make(Char)
- (** Q 1(a): implement 'mem_static'. *)
- let mem_static : char code -> CharSet.t -> bool code =
- fun c cs -> .< CharSet.mem .~c cs >.
- (** Q 1(b): implement 'mem_static_interval'. *)
- let mem_static_interval : char code -> CharSet.t -> bool code =
- fun c cs -> .< CharSet.mem .~c cs >.
- module type PSChar =
- sig
- type ps
- (** The type of partially-static characters *)
- val inj : char code -> ps
- (** Make a partially-static character from a dynamic character *)
- val in_range : ps -> char*char ->
- (ps -> 'a code) -> (ps -> 'a code) -> 'a code
- (** Test whether a character lies within a range *)
- end
- (** Q 1(c): implement PSChar *)
- module PSChar : PSChar =
- struct
- type ps = char code * CharSet.t
- let inj c = (.<.~c>., CharSet.of_list ['a'; 'b'; 'c'; 'd'; 'e'; 'f'])
- let in_range c (l,h) k1 k2 = if .<l>. <= .<.~(fst c)>. && .<.~(fst c)>. <= .<h>. then k1 c else k2 c
- end
- (** Q 1(d): implement mem_ps *)
- let mem_ps : 'a. PSChar.ps -> CharSet.t ->
- (PSChar.ps -> 'a code) -> (PSChar.ps -> 'a code) -> 'a code =
- fun c cs k1 k2 -> PSChar.in_range c ('a','f') k1 k2
- let example =
- .< fun c -> .~(mem_ps (PSChar.inj .<c>.)
- (CharSet.of_list ['a';'b';'c';'d';'e';'f'])
- (fun p -> mem_ps p
- (CharSet.of_list ['b';'d';'e';'f'])
- (fun _ -> .<"w">.)
- (fun _ -> .<"x">.))
- (fun p -> mem_ps p
- (CharSet.of_list ['c';'d';'e'])
- (fun _ -> .<"y">.)
- (fun _ -> .<"z">.))) >.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement