Guest User

Open types and down-casting in OCaml

a guest
Feb 25th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.39 KB | None | 0 0
  1. type base_type = ..
  2. class type base = object method base : base_type end
  3.  
  4. class type a' = object method baba : string method base : base_type end;;
  5. type base_type += A of a'
  6.  
  7. class a = object (self) method baba = "string" method base = A (self :> a') end
  8.  
  9. let foo () =
  10.   let a = new a in
  11.   let base = (a :> base) in
  12.   match base#base with
  13.   | A a' -> a'#baba
  14.   | _ -> assert false
Advertisement
Add Comment
Please, Sign In to add comment