caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus.mottl@gmail.com>
To: Mikhail Mandrykin <mandrykin@ispras.ru>
Cc: caml-list@inria.fr, OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Late adding of type variable constraints
Date: Fri, 11 Sep 2015 11:56:33 -0400	[thread overview]
Message-ID: <CAP_800p6Rs7BVQPnzQMxqLrPUW5yLEEeZ0HMNqrKJW+Dkh5boA@mail.gmail.com> (raw)
In-Reply-To: <1527892.mlrKSESLQ8@molnar>

On Wed, Sep 9, 2015 at 3:28 PM, Mikhail Mandrykin <mandrykin@ispras.ru> wrote:
> Probably the defunctionalization encoding used in the paper on Lightweight
> Higher-Kinded Polymorphism in OCaml
> (https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf) can help in some way. The corresponding library and examples
> are available at https://github.com/ocamllabs/higher.

Thanks a lot for this reference and your code.  Though my problem
still seems slightly different, I found this to be a very interesting
paper.  I remember reading Reynolds' work on defunctionalization many
years ago, and it's fascinating how his work translates from the
object to the type language.

> The implementation used in the library doesn't perfectly fit the case, because
> the suggested encoding puts the type `t' capturing the type skeleton on an
> unknown depth inside the list of type constructor applications.  I tried the
> following slight variation on the initial encoding:

I think the main problem for me is not so much capturing the skeleton,
which the initial approach does just fine, but that type constraints
on the polymorphic variables are maintained with mapper functions.
Maybe the more complicated approaches can be combined to solve the
problem, but that is likely not trivial.

> module Newtype1 (T : sig type 'a t end) =
> struct
>   type 'a s = 'a T.t
>   type t
>   type (_, _) typ += Mk : 'a T.t -> (('a, nil) app, t) typ
>   let inj v = Mk v
>   let prj (Mk v) = v
> end

The compiler will warn above that "prj" is not exhaustive.  If I
understand this correctly, the reasoning is that it's impossible for
two GADT constructors to yield the same type so the warning should be
spurious.  But wouldn't this require making Newtype1 a generative
functor (i.e. adding "()")?  Otherwise the type "t" could be seen as
equivalent if Newtype1 is applied to the same module more than once,
which would allow for more than one "Mk" case and could hence cause a
runtime match error.

I think for the while being I'll just stick to the syntactic approach.
Users who want to extend the number of base types to be mapped over
would have to include code with "Pair", "Option", etc. within an
environment with augmented constraints.

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com

  reply	other threads:[~2015-09-11 15:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-04 20:28 Markus Mottl
2015-09-04 22:19 ` Jacques Garrigue
2015-09-04 23:58   ` Markus Mottl
2015-09-07 18:33     ` Mikhail Mandrykin
2015-09-09 14:00       ` Markus Mottl
2015-09-09 19:28         ` Mikhail Mandrykin
2015-09-11 15:56           ` Markus Mottl [this message]
2015-09-11 16:24             ` Mikhail Mandrykin

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=CAP_800p6Rs7BVQPnzQMxqLrPUW5yLEEeZ0HMNqrKJW+Dkh5boA@mail.gmail.com \
    --to=markus.mottl@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=mandrykin@ispras.ru \
    /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).