[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jérémie Dimino <jeremie@d...> |
| Subject: | Re: [Caml-list] storing object in record |
Le mercredi 08 avril 2009 à 12:29 +0200, Michael a écrit :
> > There is no value of type: forall 'a. #baseclass as 'a.
>
> is this similar? :
>
> type 'a xx = 'a constraint 'a = < asBase: baseObject; .. > ;;
>
> (why does: type 'a xx = < asBase: baseObject; ..> as 'a not work instead? )
No, [type 'a xx = 'a constraint 'a = < asBase: baseObject; .. >] just
means that ['a] must match [< asBase : baseObject; .. >]. Actually
constraints are just inlined:
# type 'a t = 'a constraint 'a = _ * _;;
type 'a t = 'a constraint 'a = 'b * 'c
# let f (x : 'a t) = ();;
val f : ('a * 'b) t -> unit = <fun>
If you write [type 'a xx = < asBase: baseObject; ..>] (with or without
[as 'a]), then you have an unbound variable in the type definition (the
[..]).
> type 'a r = { state: 'a xx };;
>
> gives:
> type 'a r = { state : 'a xx; } constraint 'a = < asBase : baseObject; .. >
>
>
> so the record holds objects with an asBase method and more, isn't this the
> same as #baseObject?
[#baseObject] is an abbreviation for [< asBase : baseObject; .. >].
Jérémie