{-# SPECIALIZE foo @Bar #-} ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

{-# SPECIALIZE foo @Bar #-} ?

Johannes Waldmann-2
Dear Cafe,

with pragma SPECIALIZE,
I find it tedious to repeat the type declaration.
(It's a burden for maintenance and readability.)


Could we use type-application syntax instead?


E.g., the example from here
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#specialize-pragma

hammeredLookup :: Ord key => [(key, value)] -> key -> value

{-# SPECIALIZE hammeredLookup :: [(Widget, value)] -> Widget -> value #-}

would become

hammeredLookup :: forall key value . Ord key => [(key, value)] -> key ->
value

{-# SPECIALIZE hammeredLookup @Widget  #-}

or

{-# SPECIALIZE hammeredLookup @Widget @value #-}


Cf. SPECIALIZE instance, where we already write
the instantiation for the type variable(s).


- J.W.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: {-# SPECIALIZE foo @Bar #-} ?

Ganesh Sittampalam
On 08/07/2019 10:50, Johannes Waldmann wrote:

> with pragma SPECIALIZE,
> I find it tedious to repeat the type declaration.
> (It's a burden for maintenance and readability.)
>
>
> Could we use type-application syntax instead?

There's an inactive GHC proposal for this:

https://github.com/ghc-proposals/ghc-proposals/pull/15

Also a bit of discussion on this StackOverflow question:

https://stackoverflow.com/questions/39379531/how-do-i-specialise-with-an-explicit-type-application

Cheers,

Ganesh
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.