daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Apr 23rd, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module CharSet = Set.Make(Char)
  2.  
  3. (** Q 1(a): implement 'mem_static'. *)
  4. let mem_static : char code -> CharSet.t -> bool code =
  5.   fun c cs -> .< CharSet.mem .~c cs >.
  6.  
  7. (** Q 1(b): implement 'mem_static_interval'. *)
  8. let mem_static_interval : char code -> CharSet.t -> bool code =
  9.   fun c cs -> .< CharSet.mem .~c cs >.
  10.    
  11. module type PSChar =
  12. sig
  13.   type ps
  14.   (** The type of partially-static characters *)
  15.  
  16.   val inj : char code -> ps
  17.   (** Make a partially-static character from a dynamic character *)
  18.  
  19.   val in_range : ps -> char*char ->
  20.     (ps -> 'a code) -> (ps -> 'a code) -> 'a code
  21.   (** Test whether a character lies within a range *)
  22. end
  23.  
  24. (** Q 1(c): implement PSChar *)
  25. module PSChar : PSChar =
  26. struct
  27.    type ps = char code * CharSet.t
  28.    
  29.    let inj c = (.<.~c>., CharSet.of_list ['a'; 'b'; 'c'; 'd'; 'e'; 'f'])
  30.    
  31.    let in_range c (l,h) k1 k2 = if .<l>. <= .<.~(fst c)>. && .<.~(fst c)>. <= .<h>. then k1 c else k2 c
  32. end
  33.  
  34.  
  35.  
  36. (** Q 1(d): implement mem_ps *)
  37.  
  38. let mem_ps : 'a. PSChar.ps -> CharSet.t ->
  39.   (PSChar.ps -> 'a code) -> (PSChar.ps -> 'a code) -> 'a code =
  40.   fun c cs k1 k2 -> PSChar.in_range c ('a','f') k1 k2
  41.  
  42.  
  43.  
  44. let example =
  45.   .< fun c -> .~(mem_ps (PSChar.inj .<c>.)
  46.                    (CharSet.of_list ['a';'b';'c';'d';'e';'f'])
  47.                    (fun p -> mem_ps p
  48.                        (CharSet.of_list ['b';'d';'e';'f'])
  49.                        (fun _ -> .<"w">.)
  50.                        (fun _ -> .<"x">.))
  51.                    (fun p -> mem_ps p
  52.                        (CharSet.of_list ['c';'d';'e'])
  53.                        (fun _ -> .<"y">.)
  54.                        (fun _ -> .<"z">.))) >.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top