Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: Markus Mottl <mottl@miss.wu-wien.ac.at>
Cc: OCAML <caml-list@inria.fr>
Subject: Re: Problem binding type parameters in modules + subtyping and inheritance
Date: Mon, 18 Jan 1999 20:16:16 +0100	[thread overview]
Message-ID: <19990118201616.45587@pauillac.inria.fr> (raw)
In-Reply-To: <199901181707.SAA12530@miss.wu-wien.ac.at>; from Markus Mottl on Mon, Jan 18, 1999 at 06:07:56PM +0100


Hello,

> > To solve your problem, you may use functors:
> > 
> >   module type FOO1 = functor (M:sig type elt end) ->
> >   sig
> >     type foo
> >     val empty : foo
> >   end;;
> > 
> >   module Bar: FOO1 = functor (M:sig type elt end) ->
> >   struct
> >     type foo = M.elt list
> >     let empty = id [];;
> >  end;;

Another solution is to turn "empty" into a function :
   module type FOO1 = sig
     type 'a foo
     val empty : unit -> 'a foo
   end;;
   module Bar : FOO1 = struct
     type 'a foo = 'a list Lazy.t
     let empty () = lazy []
   end;;

-----------------------------------------------------------

> There just has to be a single, innocent looking class with the
> "'self"-type at the top of the inheritance hierarchie and it is impossible
> to coerce any of its descendants to any ancestor in the same line.

Actually, it is still possible to make the coercion when the type of
self only occur in covariant position (in particular, only on the
right sides of arrows) :
   class c = object (self)
     method m = self
   end;;
   class d = object (self)
     inherit c
     method n = 1
   end;;
   let x = (new d :> c);;

There is a difficulty with "binary methods", where self type occurs in
contravariant position :
   class c = object (self : 'a)
     method x = 1
     method compare (o : 'a) = self#x = o#x
   end;;
   class d = object
     inherit c
     method y = 1
   end;;
   let x = (new d :> c);;     (* Fails *)
However, you can coerce to a common supertype of c and d which has no
method "compare" :
   class type c' = object
     method x : int
   end;;
   let l = [(new c :> c'); (new d :> c')];; (* Succeeds *)

-- Jérôme




  reply	other threads:[~1999-01-19 16:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-16 12:21 Problem binding type parameters in modules Markus Mottl
1999-01-18 14:59 ` Sylvain BOULM'E
1999-01-18 17:07   ` Problem binding type parameters in modules + subtyping and inheritance Markus Mottl
1999-01-18 19:16     ` Jerome Vouillon [this message]
1999-01-18 20:37       ` Markus Mottl
1999-01-19  8:50 ` Problem binding type parameters in modules Hendrik Tews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19990118201616.45587@pauillac.inria.fr \
    --to=jerome.vouillon@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=mottl@miss.wu-wien.ac.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox