From: Mikhail Mandrykin <mandrykin@ispras.ru>
To: caml-list@inria.fr, Markus Mottl <markus.mottl@gmail.com>
Cc: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Late adding of type variable constraints
Date: Fri, 11 Sep 2015 19:24:24 +0300 [thread overview]
Message-ID: <4930712.OXrVy1QyIs@molnar> (raw)
In-Reply-To: <CAP_800p6Rs7BVQPnzQMxqLrPUW5yLEEeZ0HMNqrKJW+Dkh5boA@mail.gmail.com>
On Friday, September 11, 2015 11:56:33 AM Markus Mottl wrote:
> 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.
Yes, indeed.
module T : sig type t = int end;;
module N1 = Newtype0(T);;
module N2 = Newtype0(T);;
# N1.prj @@ N2.inj 0;;
Exception: Match_failure ("//toplevel//", 10, 10).
With generative functors this causes a typing error. In this case it's also
possible to use even simpler encoding without open types (`('a, ... ('z, nil)
app) ...) app) t'):
type ('p, 'f) app = App of 'p * 'f
type nil
module Newtype1 (T : sig type 'a t end) =
struct
type 'a t = Mk : 'a T.t -> (('a, nil) app) t
let inj v = Mk v
let prj (Mk v) = v
end
--
Mikhail Mandrykin
Linux Verification Center, ISPRAS
web: http://linuxtesting.org
e-mail: mandrykin@ispras.ru
prev parent reply other threads:[~2015-09-11 16:24 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
2015-09-11 16:24 ` Mikhail Mandrykin [this message]
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=4930712.OXrVy1QyIs@molnar \
--to=mandrykin@ispras.ru \
--cc=caml-list@inria.fr \
--cc=caml-list@yquem.inria.fr \
--cc=markus.mottl@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