Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. type good
  2. type bad
  3. type okay
  4.  
  5. type ('a, 'b) incl =
  6. | Incl_good_r : (good, good) incl
  7. | Incl_good : (good, okay) incl
  8. | Incl_bad_r : (bad, bad) incl
  9. | Incl_bad : (bad, okay) incl
  10. | Incl_okay_r : (okay, okay) incl
  11.  
  12. type _ tree =
  13. | Node : 'a tree * 'b tree * ('a, 'c) incl * ('b, 'c) incl -> 'c tree
  14. | Leaf : good tree
  15. | Stump : bad tree
  16.  
  17. let exclude_bad : type a b. (a, b) incl -> bool =
  18. function
  19. | Incl_good -> true
  20. | Incl_good_r -> true
  21. | _ -> false
  22.  
  23. (* This doesn't seem to work, though:
  24.  
  25. type ('a, 'b) incl =
  26. | Incl_refl : ('a, 'a) incl
  27. | Incl_good : (good, okay) incl
  28. | Incl_bad : (bad, okay) incl
  29.  
  30. let exclude_bad : type a b. (a, b) incl -> bool =
  31. function
  32. | Incl_good -> true
  33. | Incl_refl : (good, good) incl -> true
  34. | _ -> false
  35. *)
  36.  
  37. let rec fix_tree_type : 'a. 'a tree -> good tree =
  38. fun (type t) (tr : t tree) ->
  39. match tr with
  40. | Leaf -> Leaf
  41. | Stump -> failwith "Not a good tree"
  42. | Node (l, r, pf1, pf2) -> begin
  43. if exclude_bad pf1 && exclude_bad pf2 then
  44. Node (fix_tree_type l, fix_tree_type r, Incl_good_r, Incl_good_r)
  45. else
  46. failwith "This node stinks"
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement