caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andreas Rossberg <rossberg@mpi-sws.org>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Structural subtyping problem
Date: Sun, 28 Mar 2010 19:07:45 +0200	[thread overview]
Message-ID: <E0525766-C301-4021-A1F5-35C1A8363D26@mpi-sws.org> (raw)
In-Reply-To: <61102.44294.qm@web111503.mail.gq1.yahoo.com>


On Mar 28, 2010, at 18.38 h, Dario Teixeira wrote:

> Hi,
>
> I'm using the structural subtyping aspects of Ocaml's object system  
> to emulate width
> subtyping.  I've come across a problem which does not type-check,  
> though intuitively
> it seems correct.  I reckon that the compiler may need some help in  
> the form of type
> annotations and/or coercions, though their exact shape elludes me.
>
> A simple nonsensical example that illustrates the problem is listed  
> below; the
> type-checking error occurs in function "step1", where the optional  
> parameter "story"
> is used as an object of type "< title:string; .. >".  In function  
> "step3", this
> parameter "story" is actually instantiated with objects of type "<  
> title:string >"
> and "< title:string; count:int >".
>
> Anyway, am I correct in assuming this should be feasible?  And if  
> so, what coercions
> are required to make this compile?

You problem is just that you try to use step1 polymorphically within a  
recursion. Polymorphic recursion is not (yet) allowed in OCaml.

You can side-step it by coercing the argument to a suitable  
monomorphic type in all uses of step1. In your example, that solution  
just consists of changing step3 as follows:

> and step3 ~story = match story#count with
> 	| 0 ->
> 		let story = (story :> <title:string>)
>                 in step1 ~story ()
> 	| 1 ->
> 		...

/Andreas


  parent reply	other threads:[~2010-03-28 17:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-28 16:38 Dario Teixeira
2010-03-28 17:03 ` [Caml-list] " Vincent Aravantinos
2010-03-28 17:07 ` Andreas Rossberg [this message]
2010-03-28 17:32 ` Stéphane Glondu
2010-03-28 19:20   ` Christophe TROESTLER
2010-03-28 20:17 ` Dario Teixeira

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=E0525766-C301-4021-A1F5-35C1A8363D26@mpi-sws.org \
    --to=rossberg@mpi-sws.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=darioteixeira@yahoo.com \
    /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;
as well as URLs for NNTP newsgroup(s).