caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ben Millwood <bmillwood@janestreet.com>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Can we have more flexible destructive type substitution?
Date: Fri, 24 Jul 2015 15:25:31 +0100	[thread overview]
Message-ID: <CA+MHO51FYs9xwQ-XJ6O86sUL7Xi3A5xKM8QEhN3a7Et6bYGJ4g@mail.gmail.com> (raw)

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

Currently, for [sig ... end with type lhs := rhs] to be valid, rhs needs to
be an application of a type constructor to the same type parameters as lhs.

I'd like to do, at a minimum, [sig ... end with type 'a t := 'a], but this
is currently forbidden. Are there conceptual obstacles to permitting
arbitrary type expressions on the RHS, or are they simply not implemented
yet?

Note that I can do [type 'a id = 'a] and then [... with type 'a t := 'a
id], but it's clumsy to have to define an auxiliary type for this and it's
not always easy to find an appropriate place to do so.

In particular, I have modules with a blocking interface and an Async
interface, so I define:

module type Thing = sig
  type 'a result
  val read_thing : in_channel -> thing result
  val write_thing : out_channel -> unit result
end

thing_async.mli:
include Thing with type 'a result := 'a Deferred.t
thing_or_error.mli:
include Thing with type 'a result := 'a Or_error.t
thing_exn.mli:
include Thing with type 'a result := 'a (* fails :( *)

Having Thing_exn.id be a useless type constructor would be pretty sad.

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

             reply	other threads:[~2015-07-24 14:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-24 14:25 Ben Millwood [this message]
2015-07-24 14:37 ` Jacques Garrigue

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=CA+MHO51FYs9xwQ-XJ6O86sUL7Xi3A5xKM8QEhN3a7Et6bYGJ4g@mail.gmail.com \
    --to=bmillwood@janestreet.com \
    --cc=caml-list@inria.fr \
    /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).