[bitc-dev] Objects without subtypes
Pal-Kristian Engstad
pal_engstad at naughtydog.com
Fri Oct 17 12:06:57 CDT 2008
Jonathan S. Shapiro wrote:
> The difference in our cases is that it is possible for two structures
> that do NOT have any inheritance (row extension) relationship to exist
> simultaneously in the same scope, where both structures have a field
> named "f".
>
Actually, row-types in OCaml do indeed work like that.
let a = object method x = 0 method y = 0 end
let b = object method z = 1 method x = 0 method y = 0 end
let test_eq e f =
(e#x = f#x) && (e#y = f#y)
let res = test_eq a b
(* Output:
val a : < x : int; y : int > = <obj>
val b : < x : int; y : int; z : int > = <obj>
val test_eq : < x : 'a; y : 'b; .. > -> < x : 'a; y : 'b; .. > -> bool =
<fun>
val res : bool = true
*)
PKE.
--
Pål-Kristian Engstad (engstad at naughtydog.com),
Lead Graphics & Engine Programmer,
Naughty Dog, Inc., 1601 Cloverfield Blvd, 6000 North,
Santa Monica, CA 90404, USA. Ph.: (310) 633-9112.
"It is better to have 100 functions operate on one data structure
than 10 functions [each operate] on 10 data structures." -- NN
More information about the bitc-dev
mailing list