caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Runhang Li <runhang@posteo.net>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] GADT and weak polymorphism
Date: Thu, 19 Nov 2015 10:09:32 +0100	[thread overview]
Message-ID: <CAPFanBE2ubae7LkfsKfBLYsZ2vrHjJFjATuq2RyB8JNoCoAwHw@mail.gmail.com> (raw)
In-Reply-To: <B8C45D30-5709-4A8D-A21C-76197DE32389@posteo.net>

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

Hi Runhang,

There is an interaction between two advanced aspects of the OCaml language:

1. The relation between (non)-covariance and (non)-generalization of type
variables due to the "relaxed value restriction"

https://www.reddit.com/r/ocaml/comments/t8g2e/pdf_relaxing_the_value_restriction_by_jacques/
    http://caml.inria.fr/pub/papers/garrigue-value_restriction-fiwflp04.pdf
2. The difficult analysis of variance of GADT parameters
    https://sympa.inria.fr/sympa/arc/caml-list/2012-02/msg00059.html
    https://hal.inria.fr/hal-00772993

There is no simple way to solve any of these questions, so I don't expect
the OCaml language to improve on your example on the short/medium term.
After thinking of these issues a bit more, I would personally support
adding a notion of "pure arrow" ('a => 'b), giving your interface the type
  ( **> ) : 'c => ('a, 'b) hlist => ('c -> 'a, 'b) hlist
which would make any term built solely of ( **> ) and empty (and Empty and
Cons) generalizable. However, this feature would be very limited in scope
(due to the inherent difficulty of tracking effect) and suitable
generalization require advanced type system features (effect systems, for
example as found in Koka or F*). I think a minimal, advanced-uses-only
feature (just a separation of pure and impure arrow) would already be a
nice feature to have (also for functors), but there is no clear consensus
on the question.

On Tue, Nov 17, 2015 at 7:14 PM, Runhang Li <runhang@posteo.net> wrote:

> Hi, camels
>
> Consider the following module:
>
>     module HList = struct
>
>       type (_, _) hlist =
>         | Empty : ('a, 'a) hlist
>         | Cons  : 'c * ('a, 'b) hlist -> ('c -> 'a, 'b) hlist
>
>       let cons : type a b c. c -> (a, b) hlist -> (c -> a, b) hlist =
>         fun h tl -> Cons (h, tl)
>
>       let empty = Empty
>
>       let ( **> ) = cons
>
>       let l = '2' **> "str" **> empty
>
>     end
>
> The type of ``l`` is ``(char -> string -> ‘_a, ‘_a) hlist``. I would like
> to know the reason that weak polymorphism shows up here.
>
> Thank you
>
>
> Kindly,
>
> Runhang
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

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

  reply	other threads:[~2015-11-19  9:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17 18:14 Runhang Li
2015-11-19  9:09 ` Gabriel Scherer [this message]
2015-11-21 20:37 ` Jonas Jensen

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=CAPFanBE2ubae7LkfsKfBLYsZ2vrHjJFjATuq2RyB8JNoCoAwHw@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=runhang@posteo.net \
    /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).