[ghc-steering-committee] Proposal #281: Visible "forall" in terms; rec: accept
Simon Marlow
marlowsd at gmail.com
Wed Jun 2 09:05:56 UTC 2021
Thanks Richard and Simon - I think I understand the constraints better now.
I still find the conclusion somewhat unsatisfying, and I'm not sure I could
convincingly explain to someone why [Int] in a visible type argument means
something different from [Int] in a type signature. Intuitively it doesn't
seem unreasonable to add a little more magic to the T2T mapping to preserve
what (to me) seem to be reasonable expectations. But perhaps it's my
expectations that need to be adjusted.
Cheers
Simon
On Tue, 1 Jun 2021 at 23:43, Simon Peyton Jones via ghc-steering-committee <
ghc-steering-committee at haskell.org> wrote:
> I am generally in support.
>
>
>
> Working out the details in the dependent types proposal
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgoldfirere%2Fghc-proposals%2Fblob%2Fdependent-types%2Fproposals%2F0000-dependent-type-design.rst%23lexical-scoping-term-syntax-and-type-syntax-and-renaming&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080860069%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=rOVqniKaOfeYylK9nL7tsX2p%2Fzdv1lY5WmGchWefPjg%3D&reserved=0>
> was extremely helpful.
>
>
>
> Like Simon, I’m sad that I have to write
>
> f (List Int)
>
> or
>
> f (type [Int])
>
> but I think the alternative (of requiring the reader to know the type of
> the function in order to resolve the binding of names in its argument) is
> much, much worse.
>
>
>
> The tension here is fundamental if you want to have required type
> arguments at all. *It’s not an artefact of GHC’s history, or the
> constraints of the existing language.* (I suppose that in a new language
> you might **only** provide “List Int” and “Pair a b”, but I do like [Int]
> and (a,b) as types, and they will continue to work just fine in types.)
>
>
>
> So I have made my peace with it; and I really like the option of a “type”
> herald to switch to type syntax.
>
>
>
> Simon
>
>
>
> *From:* ghc-steering-committee <ghc-steering-committee-bounces at haskell.org>
> *On Behalf Of *Richard Eisenberg
> *Sent:* 28 May 2021 19:49
> *To:* ghc-steering-committee <ghc-steering-committee at haskell.org>
> *Subject:* [ghc-steering-committee] Proposal #281: Visible "forall" in
> terms; rec: accept
>
>
>
> Hi committee,
>
>
>
> Proposal #281 has been submitted for our consideration.
>
>
>
> Proposal PR: https://github.com/ghc-proposals/ghc-proposals/pull/281
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc-proposals%2Fghc-proposals%2Fpull%2F281&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080850077%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=fATdWkr%2FGrR8Hnf7XMqdS7T7EW9szUWI6xrl5TqEyaY%3D&reserved=0>
>
> Proposal text:
> https://github.com/int-index/ghc-proposals/blob/visible-forall/proposals/0000-visible-forall.rst
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fint-index%2Fghc-proposals%2Fblob%2Fvisible-forall%2Fproposals%2F0000-visible-forall.rst&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080850077%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=zTfCPckMrwGC6m%2F0UySVeKtA%2Fxcc1oVwR52dx4CzhK8%3D&reserved=0>
>
>
>
> The text of the proposal is long and detailed, but do not be daunted: it
> is simpler in practice than it appears.
>
>
>
> The main payload of the proposal is: Introduce a new extension
> -XRequiredTypeArguments. With this extension enabled, the `forall ... ->`
> syntax, currently in existence in kinds, is now available in types (of
> ordinary functions). This means that function definitions and call sites
> are sometimes required to write a type argument. The type argument is *not*
> preceded by @ or any other syntactic marker.
>
>
>
> This is useful for defining what would otherwise be ambiguous types.
> Example:
>
>
>
> sizeof :: forall a -> Sizeable a => Int
>
> sizeof = ...
>
>
>
> intWidth = sizeof Int
>
>
>
> There are further examples and motivation in the proposal.
>
>
>
> The rest of the proposal is simply about dealing with odd corner cases
> that come up with the main payload. In particular, mixing types in with
> terms with no syntactic signifier means that we must be careful about
> parsing and namespaces. If a type argument is written in the syntax that is
> shared between types and terms (including function application!) and uses
> identifiers in scope in only one of the two namespaces, nothing unusual can
> be observed. But, of course, there are corner cases. Here are some of the
> salient details:
>
> - Define type-syntax and term-syntax, where the choice of syntax is always
> driven by syntactic markers, such as :: or @. See the dependent types
> proposal
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgoldfirere%2Fghc-proposals%2Fblob%2Fdependent-types%2Fproposals%2F0000-dependent-type-design.rst%23lexical-scoping-term-syntax-and-type-syntax-and-renaming&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080860069%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=rOVqniKaOfeYylK9nL7tsX2p%2Fzdv1lY5WmGchWefPjg%3D&reserved=0> for
> more details. Parsing and name-resolution are controlled by whether a
> phrase is in type-syntax or term-syntax. For name resolution, if a lookup
> fails in the first namespace (the term-level namespace in term-syntax or
> the type-level namespace in type-syntax), we try the other namespace before
> failing.
>
> - Because term- vs type-syntax is controlled by syntax, a required type
> argument is in *term*-syntax and gets name-resolved *as a term*. In the
> absence of punning, this works out fine, but it is possible that a punned
> identifier will cause confusion. The proposal includes section 4.3 allowing
> users to write `type` to signify a switch to type-syntax.
>
> - The proposal also includes a way to avoid punning for the built-in types
> with privileged syntax: lists and tuples. This method allows users to
> specify -XNoListTupleTypeSyntax to disable the list and tuple syntax in
> types (but still allows it for terms). The proposal also suggests exporting
> type List = [] from Data.List and other synonyms for tuples from Data.Tuple.
>
>
>
> ---------------
>
>
>
> I recommend acceptance. When doing type-level programming, the lack of
> this feature is strange, leading to ambiguous types and easy-to-forget
> arguments and easy-to-make type errors. The design space here is difficult,
> but this proposal is very much in keeping with the design sketch of our
> recently-accepted #378, in particular its section on this point
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgoldfirere%2Fghc-proposals%2Fblob%2Fdependent-types%2Fproposals%2F0000-dependent-type-design.rst%23dependent-application-and-the-static-subset&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080860069%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=aoR7B535QjZ02sd3tI2YUyaKcV1Nf54M8TTYssRSQXQ%3D&reserved=0>.
> I believe the design described here is both backward compatible with what
> we have today (users who do not use this feature will not notice a
> difference) and forward compatible with a cohesive design for dependent
> types.
>
>
>
> There are several optional pieces:
>
> - The `type` herald
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fint-index%2Fghc-proposals%2Fblob%2Fvisible-forall%2Fproposals%2F0000-visible-forall.rst%23secondary-change-type-herald&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080870064%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=2Z%2BYU7kGwzjvxMj8OfWRpARZ5iIybqWjUSrpDtrssqU%3D&reserved=0>.
> I am unsure about this one, but others have felt strongly in favor, and I
> have no reason to object.
>
> - Types-in-terms
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fint-index%2Fghc-proposals%2Fblob%2Fvisible-forall%2Fproposals%2F0000-visible-forall.rst%23secondary-change-types-in-terms&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080870064%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=ijw%2Bp5UCXhcQ8xr%2BfvIGFI1qrM0oM%2FHrpUvzooi1vhI%3D&reserved=0>.
> I think this is necessary in order to avoid annoying definitions of type
> synonyms for one-off usage sites. It is a straightforward extension of the
> term-level parser to allow previously type-level-only constructs. It is
> necessary in order for us to achieve the vision of dependent types in #378.
> The only challenge here is that this requires us to make `forall` an
> unconditional keyword in terms. This does pose a backward-compatibility
> problem. I see, for example, that the sbv package exports a function named
> `forall`, so we may need to think more carefully about how to proceed here
> -- possibly by guarding the keyword-ness of `forall` behind the extension
> for some number of transitionary releases.
>
> - Lists and Tuples
> <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fint-index%2Fghc-proposals%2Fblob%2Fvisible-forall%2Fproposals%2F0000-visible-forall.rst%23secondary-change-lists-and-tuples&data=04%7C01%7Csimonpj%40microsoft.com%7C736617b7370942948de408d922095ee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637578248080880059%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=kI48aQDQqVp1ctxBxFLilskupxeZ3Ttqp0oUdZe3G1M%3D&reserved=0>.
> This section describes the -XNoListTupleTypeSyntax extension. I am not
> convinced that this change needs to be part of this proposal (thinking it
> belongs more in #270), but I do think we'll need it in the end. Is it OK to
> export new type synonyms from Data.List and Data.Tuple? Not sure, though
> I'd like these exported from some central place.
>
>
>
> What do others think?
>
>
>
> Thanks,
>
> Richard
> _______________________________________________
> ghc-steering-committee mailing list
> ghc-steering-committee at haskell.org
> https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-steering-committee/attachments/20210602/9d2dc919/attachment-0001.html>
More information about the ghc-steering-committee
mailing list