Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow type applications to specify type of SPECIALISE pragma #15

Closed
wants to merge 3 commits into from

Conversation

bgamari
Copy link
Contributor

@bgamari bgamari commented Oct 1, 2016

This describes an extension to the syntax of SPECIALISABLE pragmas, allowing use of type applications instead of an explicit type signature for specifying the specialised type.

Rendered


bndr: (a Haskell value-level binder)
tybndr: (a Haskell type-level binder)
type: (A Haskell type)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly it seems that the .. productionlist directive isn't recognized by GitHub's renderer.

#-}

This is, of course, quite a mouthful! Moreover, if we would at some point like
to change the type of ``foldWithParser``, we would need to updae each of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updae

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

which can then be used to fill in the type arguments of a function which we'd
like to quantify over, ::

{-# SPECIALISE forall m. foldsAndParser @m @() #-}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write

foo :: forall a b. (Ord a, Ord b) => Foo a -> Bar b
{-# SPECIALISE forall a. foo @a @a #-}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe that should be fine. The only question is whether we want to allow the introduction of new constraints, I believe. That being said, I haven't thought terribly hard about what subtleties the forall syntax might introduce.

@goldfirere
Copy link
Contributor

I think @phadej 's forall a. foo @a @a example is quite interesting. When reading the initial proposal, I thought the forall syntax was overkill, instead preferring just to use @_ to indicate unspecialized parameters. I still think @_ should be allowed, but the forall prefix allows more expressiveness, as I now understand.

@Ericson2314
Copy link
Contributor

Ericson2314 commented Oct 3, 2016

I might be jumping the gun on https://ghc.haskell.org/trac/ghc/ticket/11350, but doesn't

{-# SPECIALISE \@m -> foldsAndParser @m @() #-}

make more sense? (i.e. [capital] Lambda instead of forall)

@bgamari
Copy link
Contributor Author

bgamari commented Oct 11, 2016

John Ericson notifications@github.com writes:

I might be jumping the gun on https://ghc.haskell.org/trac/ghc/ticket/11350, but doesn't

{-# SPECIALISE \@m -> foldsAndParser @m @() #-}
``
make more sense? (i.e. the Capital Lambda instead of forall) 

Other than the fact that lambda-bound type variables aren't allowed in
normal GHC/Haskell syntax, I suppose this does make a bit more sense.

Proposed syntax
~~~~~~~~~~~~~~~

The syntax of ``SPECIALISE`` would become,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this sentence is incomplete -- unfinished section?

@rrnewton
Copy link

This seems like an interesting proposal. My only concern is this: are specialize pragmas used widely enough, in enough places by enough people, to warrant this improvement in concision?

The counterargument to this objection, IMHO, is that making a little-used feature more complicated only affects users of that feature. People who never write specialize pragmas shouldn't need to know whether this proposal is accepted or not....

@nomeata
Copy link
Contributor

nomeata commented Apr 13, 2017

Not much happening here recently. Is this soon going to be put up for discussion, Ben?

@treeowl
Copy link
Contributor

treeowl commented Apr 14, 2017

We should carefully consider how this interacts with the idea of value argument specialization, which I know has been discussed somewhere (i.e., specializing to the case where the function is applied to a particular argument). Explicit type lambdas seem to make sense in that regard.

@nomeata
Copy link
Contributor

nomeata commented May 7, 2017

Due to lack of activity, I am marking this proposal as dormant.

@nomeata nomeata added the Dormant The proposal is not being actively discussed, but can be revived label May 7, 2017
@nomeata
Copy link
Contributor

nomeata commented Feb 23, 2018

This has been dormant for a long time. @bgamari, is this abandonned? In that case, please consider closing it.

@nomeata
Copy link
Contributor

nomeata commented Apr 9, 2018

Closing due to inactivity, but it can of course be reactivated any time.

@nomeata nomeata closed this Apr 9, 2018
@bakhtiyarneyman
Copy link

bakhtiyarneyman commented Apr 11, 2019

This would come in handy in the presence of AllowAmbiguousTypes extension.

f :: forall a. C a => Int

Using Proxy/Proxy# is a workaround.

@nomeata
Copy link
Contributor

nomeata commented Nov 8, 2019

Heh, I just found myself in a situation editing big SPECIALIZE pragmas, and thought “type application would be nice? wasn’t there a proposal? surely it must have gotten accepted, I wonder which version of GHC has it”. Guess were are not there yet.

@Boarders
Copy link

I think this would be a nice quality of life improvement and it is worth re-visiting.

@dbeacham
Copy link

dbeacham commented Apr 27, 2023

I'd also love to see this.

Particularly with big SPECIALISE pragmas they're:

  1. annoying/error prone to create
  2. somewhat obfuscate what I'm wanting to achieve
  3. make code incredibly noisy when I want to specialise at multiple types

EDIT: Appears to be a special case of #493 ?

@simonpj
Copy link
Contributor

simonpj commented Apr 27, 2023

EDIT: Appears to be a special case of #493 ?

Yes! I'm enthusiastic about #493, but it just needs someone to drive it forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dormant The proposal is not being actively discussed, but can be revived
Development

Successfully merging this pull request may close these issues.

None yet