Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] When do you need a subtype before :>?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: tim@f...
Subject: [Caml-list] When do you need a subtype before :>?
It seems that sometimes when I use :> I need to use the form

   (e :> t)

and sometimes I need to use this form:

   (e : t1 :> t2)

Can anyone tell me how to predict when I need the more complicated
version?  I needed it in the code below, and that surprised me.

module type CONSCIOUS = sig
  type eventtype = [`VECTOR | `SCALAR | `UNIT]
  type +'a type_constraint
  class type [+'a] eventdesc =
    method type_constraining_field: 'a type_constraint
  class type [+'a] described_event =
    method desc: 'a eventdesc

module Foo = functor (C: CONSCIOUS) -> struct
  let _ =
    let e: [`SCALAR] C.eventdesc = failwith "x" in
    let f = (e (* No subtype needed here. *) :> C.eventtype C.eventdesc) in
  let _ =
    let e: [`SCALAR] C.described_event = failwith "ouch" in
    (* The : [`SCALAR] C.described_event on the next non-comment line is
       required, even though the same type appears on the previous
       non-comment line. *)
    let f = (e: [`SCALAR] C.described_event :> C.eventtype C.described_event)

Tim Freeman
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D  7180 76DF FE00 34B1 5C78 
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: