Skip to content

Instantly share code, notes, and snippets.

@kkismd
Created September 11, 2016 14:06
Show Gist options
  • Save kkismd/69618374aa1daebb0a28385c31b5d63f to your computer and use it in GitHub Desktop.
Save kkismd/69618374aa1daebb0a28385c31b5d63f to your computer and use it in GitHub Desktop.
(* point と colord_point の共通項を型として定義する *)
type pointable = <get_pos : int>
(* 明示的にキャストすれば同じリストにいれられる *)
let lst = [(p :> ptwointable); (cp :> pointable)]
# List.map (fun x -> x#get_pos) lst;;
- : int list = [365; 123]
(* リストに型制約をつけて宣言する *)
# let l : pointable list = [p; cp];;
Error: This expression has type point but an expression was expected of type
pointable
The second object type has no method is_equal_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment