From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Milan Stanojević" <milanst@gmail.com>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] first class module types with "with type"
Date: Thu, 29 Jan 2015 11:02:03 +0900 [thread overview]
Message-ID: <D567F874-B1BE-412D-AD27-7C1C46052F87@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAKR7PS_FG02VNkcVB6RDJFCaThbBmi=UN0URujqD0_Cm9_GZ8g@mail.gmail.com>
On 2015/01/29 08:39, Milan Stanojević wrote:
>
> My search foo is failing me, I'm pretty sure this was discussed before
> but I can't find it.
>
> Why is the following disallowed:
> module type A = sig type 'a t end
> type foo = { a : (module A with type 'a t = 'a list)}
>
> File "z.ml", line 2, characters 29-30:
> Error: Syntax error
This is because ocaml does not have higher-order polymorphism in its
core language.
Namely, the type (module S with type t = texpr) can be seen as
the type (texpr s) where
type 'a s = (module S with type t = 'a)
However, if t itself has a type parameter, we cannot turn it into a
type variable (which would have to be higher-order).
Technically, it would be possible to allow such equations, if we do not
go through the above intermediate type s. That is, we would have to
require that the type definition contains no free variables, in contrast
with non-parameterized ones for which allowing free variables is
essential.
> But this is ok
> module type A = sig type 'a t end
> module type S = A with type 'a t = 'a list
> type a = (module S)
OCaml has higher-order polymorphism in the module language.
This is what you are using in this case.
Not that from the point of view of theoretical expressivity, there is no
big difference between the two: since 4.02, equality on package types
is structural, so that it will work even if you define S twice in different
places.
Jacques Garrigue
prev parent reply other threads:[~2015-01-29 2:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-28 23:39 Milan Stanojević
2015-01-29 2:02 ` Jacques Garrigue [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=D567F874-B1BE-412D-AD27-7C1C46052F87@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=milanst@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