caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gregory Malecha <gmalecha@gmail.com>
To: Yotam Barnoy <yotambarnoy@gmail.com>
Cc: Gerd Stolpmann <info@gerd-stolpmann.de>,
	Guillaume Hennequin <g.hennequin@eng.cam.ac.uk>,
	 caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] issue with polymorphism
Date: Mon, 16 May 2016 12:09:40 -0700	[thread overview]
Message-ID: <CAGraiHK4DNEUL3gFVfAthb-eekSsU2b7vQHaU8hVKemhymMK5g@mail.gmail.com> (raw)
In-Reply-To: <CAN6ygO=C9+zbqdUZQMPoGdJyXmU-KPfKn+3a5GD-2DyV-O5DMg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2592 bytes --]

I'm not 100% familiar with the object system, but you can write them on
records.

type 'a stream = { fold : 'b . ('a -> 'b -> 'b) -> 'b -> 'b }

The reason that writing them here does not break inference is that the
inference mechanism knows that it needs to insert the universally
quantified type at the position of the record constructor, i.e. when it
sees { foo = X } it knows that it should introduce the quantifier there.
This makes it syntax-directed.



On Mon, May 16, 2016 at 12:04 PM, Yotam Barnoy <yotambarnoy@gmail.com>
wrote:

> Right, but they can't be inferred on objects and records either, and yet
> they're allowed there... so what was the rationale?
>
> On Mon, May 16, 2016 at 2:53 PM, Gregory Malecha <gmalecha@gmail.com>
> wrote:
>
>> There may other reasons as well, e.g. performance and compilability, but
>> the main reason that I know is that inferring these types is difficult
>> (undecideable in general). For a point of comparison, GHC supports types
>> like this, but only when they are explicitly written.
>>
>> On Mon, May 16, 2016, 11:50 AM Yotam Barnoy <yotambarnoy@gmail.com>
>> wrote:
>>
>>> Paging the type experts -- is there a concrete reason why we disallow
>>> writing this type directly?
>>>
>>> On Mon, May 16, 2016 at 1:32 PM, Gerd Stolpmann <info@gerd-stolpmann.de>
>>> wrote:
>>>
>>>> Am Montag, den 16.05.2016, 17:55 +0100 schrieb Guillaume Hennequin:
>>>> > Thanks all for your prompt answers;
>>>> >
>>>> > > See the FAQ entry, "How to write a function with polymorphic
>>>> arguments?"
>>>> > >
>>>> https://ocaml.org/learn/faq.html#Howtowriteafunctionwithpolymorphicarguments
>>>> >
>>>> > this page explains how to do it with records or objects, but ends
>>>> with a
>>>> > mysterious "FIXME: a direct way now exists". Does anyone know what
>>>> this might
>>>> > refer to?
>>>>
>>>> What you would need is
>>>>
>>>> let print_both : ('a . 'a -> 'a) -> unit = ...
>>>>
>>>> i.e. the scope of the quantifier is restricted to the first argument.
>>>> This doesn't exist to my knowledge. Maybe it was part of some dev
>>>> version?
>>>>
>>>> Gerd
>>>> --
>>>> ------------------------------------------------------------
>>>> Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
>>>> My OCaml site:          http://www.camlcity.org
>>>> Contact details:        http://www.camlcity.org/contact.html
>>>> Company homepage:       http://www.gerd-stolpmann.de
>>>> ------------------------------------------------------------
>>>>
>>>>
>>> --
>>
>> - gregory malecha
>>   gmalecha.github.io
>>
>
>


-- 
gregory malecha
gmalecha.github.io

[-- Attachment #2: Type: text/html, Size: 4722 bytes --]

  reply	other threads:[~2016-05-16 19:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-16 15:45 Guillaume Hennequin
2016-05-16 15:57 ` Gabriel Scherer
2016-05-16 16:55   ` Guillaume Hennequin
2016-05-16 17:32     ` Gerd Stolpmann
2016-05-16 18:49       ` Yotam Barnoy
2016-05-16 18:53         ` Gregory Malecha
2016-05-16 19:04           ` Yotam Barnoy
2016-05-16 19:09             ` Gregory Malecha [this message]
2016-05-16 15:57 ` Nicolas Ojeda Bar

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=CAGraiHK4DNEUL3gFVfAthb-eekSsU2b7vQHaU8hVKemhymMK5g@mail.gmail.com \
    --to=gmalecha@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=g.hennequin@eng.cam.ac.uk \
    --cc=info@gerd-stolpmann.de \
    --cc=yotambarnoy@gmail.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).