Hello, guys!
There is code:
exception Unmatched_Struct;;
class virtual flow aid =
object
val id : int = aid
method gid : int = aid
end;;
class rnone =
object
inherit flow 0 as super
end;;
class ['a] rsome avalue =
object
inherit flow 1 as super
val fvalue : 'a = avalue
method gvalue : 'a = avalue
end;;
let maybeMap m f =
match (m)#gid with
| (*None*) 0 -> new rnone
| (*Some*) 1 -> let v = m#gvalue in
new rsome (f (v))
| _ -> raise Unmatched_Struct ;;
Compilation gives:
Error: This expression has type 'a rsome
but an expression was expected of type rnone
The second object type has no method gvalue
Second object definitely has no gvalue method, but what about having different type of rnone and rsome? Both are inherited from flow.