
I've just noticed that there is no GHC language extension for annotations http://www.haskell.org/ghc/docs/latest/html/users_guide/extending-ghc.html#a... That feels like an oversight. Yes, they are in a pragma, but you may get an error message if you compile with a stage-1 compiler, for example. Plus, the language extensions should truthfully report what extra stuff you are using. I'm inclined to add a language extension "Annotations". * Without it {-# ANN ... #-} pragmas are ignored as comments * With it, they are treated as annotations Do you agree? I don't know whether this can (or even should) land in 7.8.1. Do you care either way? Guidance welcome Simon Microsoft Research Limited (company number 03369488) is registered in England and Wales Registered office is at 21 Station Road, Cambridge, CB1 2FB

I agree. I would like a warning if I use {-# ANN ... #-} without the
language pragma. I clearly meant to write an annotation!
On Wed, Nov 6, 2013 at 11:55 AM, Simon Peyton-Jones
I’ve just noticed that there is no GHC language extension for annotations
http://www.haskell.org/ghc/docs/latest/html/users_guide/extending-ghc.html#a...
That feels like an oversight. Yes, they are in a pragma, but you may get an error message if you compile with a stage-1 compiler, for example. Plus, the language extensions should truthfully report what extra stuff you are using.
I’m inclined to add a language extension “Annotations”.
· Without it {-# ANN … #-} pragmas are ignored as comments
· With it, they are treated as annotations
Do you agree?
I don’t know whether this can (or even should) land in 7.8.1. Do you care either way?
Guidance welcome
Simon
*Microsoft Research Limited (company number 03369488) is registered in England and Wales *
*Registered office is at 21 Station Road, Cambridge, CB1 2FB*
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

On Wed, 6 Nov 2013 10:55:09 +0000, Simon Peyton-Jones
I’m inclined to add a language extension “Annotations”.
· Without it {-# ANN … #-} pragmas are ignored as comments
· With it, they are treated as annotations
Do you agree?
I generally agree that this should be a language extension. My only worry is around the just implemented TH additions regarding annotations. I don't clearly see what would happen if: - a TH library exports a function that generates annotations when spliced. - and the user uses this function in a .hs file, - without specifying the language extension. I'd it to work even in that case. I guess the behavior in this corner case depends heavily on how this is actually implemented. If e.g. the reader is the only component that checks if the language extension is turned on, then I imagine that the TH way of putting in the annotation into the AST would just work. On the other hand if the reader recognizes the annotations either way and some component after TH splicing is checking for the language extension, then my use-case would blow up. TH currently is lenient in cases like this. E.g. if you know that a Name is exported from a module and you reference it directly, without importing it everything will just work. I'd like to have the same behavior for annotations. Thanks, Gergely

| My only worry is around the just implemented TH additions regarding
| annotations. I don't clearly see what would happen if:
| - a TH library exports a function that generates annotations when
| spliced.
| - and the user uses this function in a .hs file,
| - without specifying the language extension.
But this is true for ANY language extension. If a TH library exports a function that generates (say) a type family declaration, and you splice that into a file, do you need -XTypeFamilies in the client file? I think currently you do.
So your point is a good one but it's orthogonal.
Simon
| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of
| Gergely Risko
| Sent: 06 November 2013 11:57
| To: ghc-devs@haskell.org
| Cc: glasgow-haskell-users@haskell.org
| Subject: Re: Annotations
|
| On Wed, 6 Nov 2013 10:55:09 +0000, Simon Peyton-Jones
|

[sorry if someone receives this twice, apparently gmane has some issues with crossposting]
[this is also my reply to Ekmett's comment]
On Wed, 6 Nov 2013 12:06:04 +0000, Simon Peyton-Jones
But this is true for ANY language extension. If a TH library exports a function that generates (say) a type family declaration, and you splice that into a file, do you need -XTypeFamilies in the client file? I think currently you do.
So, we've made a little bit of testing on this. There are a lot of extensions that simply can't be used with TH: - n+k, - RecursiveDo, - TransformListComp, - Arrows, - ImplicitParams, - TupleSections, - Monadcomprehensions. The rest can be grouped into two parts. The following extensions still work when spliced in without the corresponding language pragma: - UnicodeSyntax, - LambdaCase, - NamedFieldPuns, - RecordWildCards, - DataTypeContexts (and you get rid of the deprecation warning generation this way :)), - ConstraintKind, - MagicHash (note that UnboxedTuples is in the other part), - TraditionalRecordSyntax, - MultiWayIf, - GADTs (extra nice example at the end of this message). The following needs the pragma at the place of splicing: - PostfixOperators, - ScopedTypeVariables, - Rank2, RankN, - deriving typeable and data, - UnboxedTuples, - ViewPatterns, - ParallelListComp, - ExistentialQuantification, - EmptyDataDecls, - TypeFamilies, - MultiParamTypeClasses, - FunctionalDependencies. I don't see any trivial distinction, like based on Reader vs Typechecker or anything like that. Note ViewPatterns vs LambdaCase. Note GADTs vs Rank2. A very interesting example is ExplicitForAll. The AST for polymorphic functions always have explicit foralls in TH.Syntax; so there is no way to require the user at the point of splicing to enable the language extension. GADTs are cool to: ------------------------------ {-# LANGUAGE TemplateHaskell #-} -- No need for GADTs at all! -- {-# LANGUAGE GADTs #-} $([d| data Foo where Foo1 :: Int -> Foo Foo2 :: String -> Foo f1 :: Foo f1 = Foo1 5 f :: Foo -> Either Int String f (Foo1 n) = Left n f (Foo2 s) = Right s |]) main = print (f f1) ------------------------------ So all I'm asking for is that if it's not very inconvenient for the implementor, please put the Annotations language pragma into the first group. :) Thanks, Gergely

Currently, in all the cases I can think of if the splice generates something that uses an extension then the module must have that flag turned on. Sent from my iPhone
On Nov 6, 2013, at 6:57 AM, Gergely Risko
wrote: On Wed, 6 Nov 2013 10:55:09 +0000, Simon Peyton-Jones
writes: I’m inclined to add a language extension “Annotations”.
· Without it {-# ANN … #-} pragmas are ignored as comments
· With it, they are treated as annotations
Do you agree?
I generally agree that this should be a language extension.
My only worry is around the just implemented TH additions regarding annotations. I don't clearly see what would happen if: - a TH library exports a function that generates annotations when spliced. - and the user uses this function in a .hs file, - without specifying the language extension.
I'd it to work even in that case.
I guess the behavior in this corner case depends heavily on how this is actually implemented. If e.g. the reader is the only component that checks if the language extension is turned on, then I imagine that the TH way of putting in the annotation into the AST would just work.
On the other hand if the reader recognizes the annotations either way and some component after TH splicing is checking for the language extension, then my use-case would blow up.
TH currently is lenient in cases like this. E.g. if you know that a Name is exported from a module and you reference it directly, without importing it everything will just work. I'd like to have the same behavior for annotations.
Thanks, Gergely
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

On Wed, 6 Nov 2013 10:55:09 +0000, Simon Peyton-Jones
I’ve just noticed that there is no GHC language extension for annotations
http://www.haskell.org/ghc/docs/latest/html/users_guide/extending-ghc.html#a... pragmas
That feels like an oversight. Yes, they are in a pragma, but you may get an error message if you compile with a stage-1 compiler, for example. Plus, the language extensions should truthfully report what extra stuff you are using.
And are you more inclined because of the stage-1 incompatibility or because of the second reason: "the language extensions should truthfully report what extra stuff you are using". Because in the second case, then maybe we should do the same for: - inlining, - SPECIALIZE, - unpacking, - rules. All of these also have TH implementation, so the same kind of issue would arise for them. I agree that my issue is orthogonal, but I still see it as important. For example when generating small boilerplate functions via TH, then you almost always want to add the INLINE pragma without bothering the user. I'd vote for doing this (even only for annotations, if you only want that). But would really like to handle the TH issue at the same time. About MultiParamTypeClasses, I think you're correct. But I'm not so sure that this is general for ALL the language pragmas, I'll try them out and report back if I find further inconsistencies. Gergely

Simon, Austin and I discussed this briefly yesterday. There's an existing ticket: http://ghc.haskell.org/trac/ghc/ticket/4268 I added a comment to the ticket to summarise our conclusion: we won't add a flag for the pragma, however we should add a warning when an ANN pragma is being ignored. On 06/11/2013 10:55, Simon Peyton-Jones wrote:
I’ve just noticed that there is no GHC language extension for annotations
http://www.haskell.org/ghc/docs/latest/html/users_guide/extending-ghc.html#a...
That feels like an oversight. Yes, they are in a pragma, but you may get an error message if you compile with a stage-1 compiler, for example. Plus, the language extensions should truthfully report what extra stuff you are using.
I’m inclined to add a language extension “Annotations”.
·Without it {-# ANN … #-} pragmas are ignored as comments
·With it, they are treated as annotations
Do you agree?
I don’t know whether this can (or even should) land in 7.8.1. Do you care either way?
Guidance welcome
Simon
/Microsoft Research Limited (company number 03369488) is registered in England and Wales /
/Registered office is at 21 Station Road, Cambridge, CB1 2FB/
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs
participants (5)
-
Edward A Kmett
-
Gergely Risko
-
Johan Tibell
-
Simon Marlow
-
Simon Peyton-Jones