[Haskell-cafe] Proposal: Shorter Import Syntax

Herbert Valerio Riedel hvr at gnu.org
Sun Jun 7 06:09:20 UTC 2015

On 2015-06-07 at 02:18:47 +0200, Anthony Cowley wrote:
> On Sat, Jun 6, 2015 at 6:35 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:
>> On 2015-06-04 at 23:36:01 +0200, Anthony Cowley wrote:
>>>> On Jun 4, 2015, at 5:22 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:
>>>>> On 2015-06-04 at 23:05:42 +0200, Alexey Shmalko wrote:
>>>>> If I understand correctly, the initial proposal was to enable the new
>>>>> syntax by default and it mustn't break any code (full
>>>>> backward-compatible).
>>>> That would be a departure from how language extensions were handled in
>>>> GHC in the past afaik, and if there's no language pragma to toggle this
>>>> new syntax, Cabal has no way to know that a new language syntax is
>>>> required and that thereby needs exclude (not implemented yet) the
>>>> affected package versions from the install-plan configuration space.
>>> I can't parse your last sentence.
>> I'll rephrase: Extending the syntax GHC accepts beyond H2010 w/o a
>> language flag (but if I understood you correctly, you stated that
>> there's gonna be an associated language pragma) is not desirable, since you
>> wouldn't be able communicate that requirement to Cabal via the
>> other-extensions/default-extensions mechanism (albeit that information
>> is currently not used early enough to affect the install-plan solver,
>> see also [1])
>> While I'm mildly against having this new syntax enabled in GHC's
>> default-mode (i.e. when neither -XHaskell2010 nor -XHaskell98 is set),
>> I'm strongly against enabling it implicitly via -XHaskell2010, as when
>> you request -XHaskell2010 you want GHC ideally to tell you when you're
>> using syntax beyond H2010.
> Just to be clear, that ideal is not reality, is it? I can pass ghc
> -XHaskell2010 and use syntactic extensions in my programs today (e.g.
> LambdaCase).

*Only* if you also explicitly enable them, e.g. if you have a module which
only contains

  {-# LANGUAGE Haskell2010 #-}

and let's assume for simplicity there are no additional -X* flags passed
via the CLI to GHC, then you can't use syntactic extensions like
LambdaCase; i.e. the following module

  {-# LANGUAGE Haskell2010 #-}
  module M1 where

  f :: () -> ()
  f = \case
    () -> ()

when compiled with `ghc -Wall -c M1.hs` is rightfully rejected with:

  M1.hs:6:5: parse error: naked lambda expression ''

However, if an additional `{-# LANGUAGE LambdaCase #-} is added, GHC
compiles it w/o any complaint.

> I can additionally pass ghc -Wall and not hear about it.
> So I think what you're writing here is a proposal for a new GHC
> feature that restricts available syntactic extensions in the presence
> of a language standard flag?

Maybe I was unclear, but I didn't mean that -XHaskell2010 should enable
additional warnings for additionally *requested* language extensions.

If I write

  {-# LANGUAGE Haskell2010       #-}
  {-# LANGUAGE LambdaCase        #-}
  {-# LANGUAGE DefaultSignatures #-}
  {-# LANGUAGE RecordWildcards   #-}
into a module, I explicitly state that the code requires Haskell2010
syntax *with* additionally those 3 syntax extensions enabled (which btw
are syntax extensions that afaik don't break any legal Haskell2010, and
hence could be enabled by default -- but GHC doesn't enable them by
default either!). There's obviously no point in warning if I really make
use of those additional language extension, as that's what the
pragma-mechanism is for in the first place.

> The interplay between things like Haskell2010 and other language
> extensions isn't great. It would be nice to have a better story, but I
> think that really is a separate issue wherein you want Haskell2010 to
> act like a meta-pragma to ensure that the file really is Haskell2010
> compatible. I am not volunteering to make that happen :)

To be clear, I only meant to say that the presence of -XHaskell2010 (or
equivalently, {-# LANGUAGE Haskell2010 #-}) *without* any additional -X
flags or LANGUAGE-pragmas is supposed to enable only the minimum
required syntax extensions to provide the Haskell2010 syntax, as any
syntax beyond Haskell2010 ought to be provided via -X/LANGUAGE pragmas.

See also


which states that

| By default, GHC mainly aims to behave (mostly) like a Haskell 2010
| compiler, although you can tell it to try to behave like a particular
| version of the language with the -XHaskell98 and -XHaskell2010 flags.

and fwiw GHC's default-mode is not the same as -XHaskell2010

More information about the Haskell-Cafe mailing list