caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Didier Remy <Didier.Remy@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Equality between abstract type definitions
Date: Sat, 26 Oct 2013 16:11:10 +0200	[thread overview]
Message-ID: <526BCD7E.6030505@inria.fr> (raw)
In-Reply-To: <20131026090711.13453.qmail@www1.g3.pair.com>

> Since all type variables in Haskell are rigid, there is no longer any
> convenient way to tell GHC that I think two sub-expression in a large
> definition should have the same type. That's a pity. OCaml's type
> variables are great for that. OCaml type variables can be understood
> purely declaratively, as an assertion from the programmer that all
> sub-expressions marked by the same type variables must have the same
> type, whatever it turns out to be. I often feel the need for such
> annotations in Haskell. There are workarounds, but they are ugly.

Indeed, both forms are useful, since in a system that does type inferenece I
may wish to specify part of the annotations but not all of it.  Rigid
variables will make the type checker complain if the inferred type is weaker
than what I expected and flexible variables allow me to omit parts of types
that I don't care about or just say that two parts of a type should be the
same without caring what these parts exactly are.

    For example, one should be able to express annotations of the form:

        for all 'a, 'b, for some 'u, ('a -> 'b) -> 'a * 'u -> 'b * 'u

    where 'u, 'v are flexible but 'a, 'b are rigid.

    Bindings should not just be in a single type annotations but in programs,
    so that two arguments can for instance be requested to have the same type.

        let g =
            let f (for some 'a) (x : 'a) (y : 'a) = ... in
        in ...

    Notice, that the inner binding has a limited scope,  which allows
    variables that will appear in the type inferred for 'a to be generalized
    in the type of f.

In fact, now that existential variables have been introduced in the
language, via local modules or gadts, there are three kinds of bindings:
rigid (universal or existential) and flexible variables. Even though
universal and existential are treated in the same way as rigid variables
which cannot be instantiated, their meaning is different and we should
probaly reflect this by a syntactic difference.

Hence, a good design (if we were to redo it from scratch) should require the
user to always explicitly bind type variables, forcing him to say how and
were there are bound.

     Didier


  reply	other threads:[~2013-10-26 14:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-24 22:57 Peter Frey
2013-10-24 23:23 ` Jacques Garrigue
2013-10-25  6:44   ` Andreas Rossberg
2013-10-25  8:29     ` Roberto Di Cosmo
2013-10-25  9:59       ` Ivan Gotovchits
2013-10-25 11:09         ` Gabriel Scherer
2013-10-25 14:24           ` Andreas Rossberg
2013-10-25 20:32             ` Yaron Minsky
2013-10-25 20:44               ` Jacques Le Normand
2013-10-26  1:08                 ` Norman Hardy
2013-10-26  5:28                   ` Jacques Garrigue
2013-10-27 12:16               ` Andreas Rossberg
2013-10-27 12:56                 ` Yaron Minsky
2013-10-27 14:28                   ` Gabriel Scherer
2013-10-27 14:43                     ` Yaron Minsky
2013-10-27 15:25                       ` Gabriel Scherer
2013-10-27 15:41                         ` Yaron Minsky
2013-10-25 12:35         ` Roberto Di Cosmo
2013-10-25 12:45           ` Jonathan Protzenko
2013-10-25 13:20             ` Roberto Di Cosmo
2013-10-25 14:03       ` Andreas Rossberg
2013-10-26  9:07         ` oleg
2013-10-26 14:11           ` Didier Remy [this message]
2013-10-26 17:32         ` Didier Remy
2013-10-27 12:07           ` Andreas Rossberg
2013-10-27 14:10             ` Roberto Di Cosmo
2013-10-28  3:30     ` 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=526BCD7E.6030505@inria.fr \
    --to=didier.remy@inria.fr \
    --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).