[ghc-steering-committee] Discussion on proposal #99: forall {k}
Simon Peyton Jones
simonpj at microsoft.com
Tue May 1 10:55:28 UTC 2018
[Redirecting to the steering committee]
I argue for acceptance.
* For me a compelling motivation is this: at the moment we can infer types and kinds that we cannot write down with an explicitly-quantified type signature. That seems all wrong to me: we should be able to write down any type you can infer.
* The proposal adds notation. It does not add semantics. We already have the distinction between “inferred” and “specified” type variables. You might not like it, but it’s there in GHC.
* If it wasn’t there already, I’d be happy to debate not adding it.
* If you want to argue for removing the distinction, that would certainly render the current proposal moot. But that would take a GHC proposal – and there are good reasons for the status quo!
* What is bad is to maintain the semantic distinction, but be unable to express it. That’s what we have right now, and it’s a bad thing.
What is the distinction between “specified” and “inferred”?
* Specified. f :: forall a. blah, or f :: a -> a.
You may give a visible type argument at a call of f, but you do not have to. Thus (f x) or (f @type x).
* Inferred. f :: t a -> t a. The type of f is really
g :: forall {k} (t :: k -> *) (a :: k). t a -> t a
Note that k does not appear at all in the signature; that’s why it is “inferred”. In GHC today you cannot supply an explicit kind argument for g, but you can supply explicit argument for t and a.
So by all means make the case for abolishing the distinction, to render the present proposal moot. But I think it’s unreasonably simply to reject on the grounds of “please think of something better”.
Simon
From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Iavor Diatchki
Sent: 30 April 2018 17:12
To: ghc-devs at haskell.org
Subject: Discussion on proposal #99: forall {k}
Hello,
As a shepherd for proposal #99, I'd like to kick off the discussion. The full proposal is available here: https://github.com/goldfirere/ghc-proposals/blob/explicit-specificity/proposals/0000-explicit-specificity.rst
Summary: allows programmers to write `forall {x}` instead of `forall x` in type signatures. The meaning of the braces is that this parameter cannot be instantiated with an explicit type application and will always be inferred. The motivation is to shorten explicit type applications by skipping parameters that are known to be inferable, the common example being omitting the kinds in signatures with poly kinds.
As I understand it, the main motivation for this proposals is to give programmers more flexibility when instantiating type variables, with a less noisy syntax. While the proposed solution might work in some situations, I am unconvinced that it is the best way to address the issue in general, for the following reasons:
1. It requires that programmers commit at declaration time about which arguments will be inferred, and which may be inferred or specified. While in some cases this may be an easy decision to make, in many cases this really is a decision which should be made at the use site of a function (e.g., I'd like to provide argument X, but would like GHC to infer argument Y).
2. It still requires that programmers instantiate arguments in a fixed order, which is sometimes dictated by the structure of the type itslef. Here is, for example, what the proposal suggests to do if you want to provide type before a kind:
typeRep4 :: forall {k} (a :: k) k'. (k ~ k', Typeable a) => TypeRep a
While technically this is not wrong, it is not exactly elegant.
I think that we should reject this proposal, and try to come up with a more comprehensive solution to the problem.
One alternative design is to allow programmers to instantiate type variables by name. This is much more flexible as it allows programmers to instantiate whichever variables they want, and in whatever order. We've been doing this in Cryptol for a long time, and it seems to work really well.
-Iavor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-steering-committee/attachments/20180501/09e8edde/attachment-0001.html>
More information about the ghc-steering-committee
mailing list