Re: Overlapping and incoherent instances

On 2014-07-29 at 11:29:45 +0200, Niklas Hambüchen wrote:
instance {-# OVERLAPPABLE #-} Show a => Show [a] where …
Is the syntax somewhat flexible in where the pragma can be placed? For example, some might prefer
{-# OVERLAPPING #-} instance Show [Char] where …
This variant may also be more convenient in cases where you need to CPP-guard that pragma, as it's on a separate line.

On Tue, Jul 29, 2014 at 11:50 AM, Herbert Valerio Riedel
On 2014-07-29 at 11:29:45 +0200, Niklas Hambüchen wrote:
instance {-# OVERLAPPABLE #-} Show a => Show [a] where …
Is the syntax somewhat flexible in where the pragma can be placed? For example, some might prefer
{-# OVERLAPPING #-} instance Show [Char] where …
This variant may also be more convenient in cases where you need to CPP-guard that pragma, as it's on a separate line.
Agreed, and if we remove the old pragma (even with a deprecation cycle) you'll see quite a few of those as many library authors try to have their libraries compile with the last 3 major GHC versions. P.S. For e.g. INLINABLE we require that you mention the function name next to the pragma (which means that you can e.g. put the pragma after the declaration). What's the rationale to not require {-# OVERLAPPING Show [Char] #-} here? Perhaps it's too annoying to have to repeat the types?

On Tue, Jul 29, 2014 at 12:02:19PM +0200, Johan Tibell wrote:
What's the rationale to not require
{-# OVERLAPPING Show [Char] #-}
here? Perhaps it's too annoying to have to repeat the types?
This one might be written at the top of the file, so it would be easier to overlook it, than having it directly at the instance declaration, which seems to be one of the major points for OVERLAPPING and OVERLAPPABLE. Greetings, Daniel

On Tue, Jul 29, 2014 at 12:37 PM, Daniel Trstenjak
On Tue, Jul 29, 2014 at 12:02:19PM +0200, Johan Tibell wrote:
What's the rationale to not require
{-# OVERLAPPING Show [Char] #-}
here? Perhaps it's too annoying to have to repeat the types?
This one might be written at the top of the file, so it would be easier to overlook it, than having it directly at the instance declaration, which seems to be one of the major points for OVERLAPPING and OVERLAPPABLE.
The same could be said for e.g. INLINE. The extra flexibility is nice to have (e.g. because you can opt to put the pragma after the declaration, to de-emphasize it.)

I think it may also lead to cleaner code. I would rather write a single
section like this:
#if NEW_GHC
{-# bunch of OVERLAPPABLE declarations #-}
#endif
at the start of the file rather than have to insert a lot of CPP-guarded
pragmas later. But it may be seen as an editor/IDE issue and bikeshedding
on the whole.
--
Krzysztof
On Tue, Jul 29, 2014 at 12:48 PM, Johan Tibell
On Tue, Jul 29, 2014 at 12:37 PM, Daniel Trstenjak
wrote: On Tue, Jul 29, 2014 at 12:02:19PM +0200, Johan Tibell wrote:
What's the rationale to not require
{-# OVERLAPPING Show [Char] #-}
here? Perhaps it's too annoying to have to repeat the types?
This one might be written at the top of the file, so it would be easier to overlook it, than having it directly at the instance declaration, which seems to be one of the major points for OVERLAPPING and
OVERLAPPABLE.
The same could be said for e.g. INLINE. The extra flexibility is nice to have (e.g. because you can opt to put the pragma after the declaration, to de-emphasize it.) _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

The current implementation requires the pragma exactly where showed it.
I'm not keen on allowing it to be separated.
I suppose with some more parser jiggery pokery it could be allowed immediately before (or, better, after).
But cpp would let you say
instance
#if blah
{-# OVERLAPPABLE #-}
#endif
Show a => Show [a] where ...
Simon
| -----Original Message-----
| From: Johan Tibell [mailto:johan.tibell@gmail.com]
| Sent: 29 July 2014 11:02
| To: Herbert Valerio Riedel
| Cc: Niklas Hambüchen; Haskell Libraries (libraries@haskell.org); GHC
| users; Simon Peyton Jones; ghc-devs
| Subject: Re: Overlapping and incoherent instances
|
| On Tue, Jul 29, 2014 at 11:50 AM, Herbert Valerio Riedel

I think one nice thing about this proposal is that it doesn't seem (to me) to require CPP around the pragma: unrecognized pragmas are warned about but are otherwise harmless. Are folks very keen to have *warning-free* compilation on several GHC versions? Personally, I would aim for warning-free compilation on a most recent version, and otherwise successful compilation on older versions.
The only place CPP would be needed is around the LANGUAGE pragma, in order to avoid the deprecation warning in 7.10.
One other issue this brings up: how does this all interact with -XSafe? Right now, Safety can be inferred by looking at the set of LANGUAGE pragmas and the import list. (Right?) With the change as implemented, Safe inference would require looking at all instance declarations. Is this OK?
Richard
On Jul 29, 2014, at 7:02 AM, Simon Peyton Jones
The current implementation requires the pragma exactly where showed it.
I'm not keen on allowing it to be separated.
I suppose with some more parser jiggery pokery it could be allowed immediately before (or, better, after).
But cpp would let you say
instance #if blah {-# OVERLAPPABLE #-} #endif Show a => Show [a] where ...
Simon
| -----Original Message----- | From: Johan Tibell [mailto:johan.tibell@gmail.com] | Sent: 29 July 2014 11:02 | To: Herbert Valerio Riedel | Cc: Niklas Hambüchen; Haskell Libraries (libraries@haskell.org); GHC | users; Simon Peyton Jones; ghc-devs | Subject: Re: Overlapping and incoherent instances | | On Tue, Jul 29, 2014 at 11:50 AM, Herbert Valerio Riedel
| wrote: | > On 2014-07-29 at 11:29:45 +0200, Niklas Hambüchen wrote: | >>> instance {-# OVERLAPPABLE #-} Show a => Show [a] where … | >> | >> Is the syntax somewhat flexible in where the pragma can be placed? | >> For example, some might prefer | >> | >> {-# OVERLAPPING #-} | >> instance Show [Char] where … | > | > This variant may also be more convenient in cases where you need to | > CPP-guard that pragma, as it's on a separate line. | | Agreed, and if we remove the old pragma (even with a deprecation | cycle) you'll see quite a few of those as many library authors try to | have their libraries compile with the last 3 major GHC versions. | | P.S. For e.g. INLINABLE we require that you mention the function name | next to the pragma (which means that you can e.g. put the pragma after | the declaration). What's the rationale to not require | | {-# OVERLAPPING Show [Char] #-} | | here? Perhaps it's too annoying to have to repeat the types? _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

| One other issue this brings up: how does this all interact with -XSafe?
| Right now, Safety can be inferred by looking at the set of LANGUAGE
| pragmas and the import list. (Right?) With the change as implemented,
| Safe inference would require looking at all instance declarations. Is
| this OK?
I'm honestly not sure, but I do know that, in the implementation, each instance declaration keeps track of (a) whether it is OVERLAPPABLE/OVERLAPPING/INCOHERENT, and (b) the setting of -XSafe in the module where the instance declaration is given.
This doesn't change. So I can't answer your question directly, but I think that the behaviour is unchanged from that at present.
Simon
|
| Richard
|
| On Jul 29, 2014, at 7:02 AM, Simon Peyton Jones
participants (6)
-
Daniel Trstenjak
-
Herbert Valerio Riedel
-
Johan Tibell
-
Krzysztof Skrzętnicki
-
Richard Eisenberg
-
Simon Peyton Jones