caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] When do you need a subtype before :>?
@ 2002-09-09  5:34 Tim Freeman
  2002-09-09  6:20 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Tim Freeman @ 2002-09-09  5:34 UTC (permalink / raw)
  To: caml-list

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 =
  object
    method type_constraining_field: 'a type_constraint
  end
            
  class type [+'a] described_event =
  object
    method desc: 'a eventdesc
  end
                          
end

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)
    in
      ()
end

-- 
Tim Freeman       
tim@fungible.com
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D  7180 76DF FE00 34B1 5C78 
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-09-09  6:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-09  5:34 [Caml-list] When do you need a subtype before :>? Tim Freeman
2002-09-09  6:20 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).