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

How to override default-language to GHC2021 (for use with GHC9.2.2) #5739

Closed
maerten opened this issue May 10, 2022 · 8 comments
Closed

How to override default-language to GHC2021 (for use with GHC9.2.2) #5739

maerten opened this issue May 10, 2022 · 8 comments

Comments

@maerten
Copy link

maerten commented May 10, 2022

How to set default-language to GHC2021 instead of Haskell2010?
When using stack in a project, it sets the default-language in the generated cabal file to Haskell2010. Afaik, this disables some modules that would otherwise be enabled by default in GHC9.2.x (via the GHC2021 language extension).

Any suggestions on how to work around this behavior of stack?

@mpilgrem
Copy link
Member

mpilgrem commented May 10, 2022

stack can use hpack (but does not need to) and hpack before version 0.35.0 assumes Haskell2010 by default. Very recently, the stack code on this repository was updated to use hpack-0.35.0. So you could upgrade to the unreleased version of stack, by stack upgrade --source-only.

EDIT: Alternatively, you could install locally version 0.35.0 of the hpack executable and then use stack --with-hpack <hpack executable> to use that version of hpack rather than the version 'built in' to your existing version of the stack executable (revealed by the command stack --hpack-numeric-version).

Alternatively, you could not use hpack at all. Delete the package.yaml file (which hpack uses to create a .cabal file) and specify the .cabal file directly, including your preferred default-language.

@maerten
Copy link
Author

maerten commented May 11, 2022

Thanks @mpilgrem, I did not know about hpack and package.yaml.

FYI: stack upgrade --source-only did not update stack, it said the newest version was already installed. This might be the case because I installed it with ghcup.

The trick with hpack worked perfectly though:

  1. stack install hpack-0.35.0 --resolver=nightly-2022-05-05
  2. stack --with-hpack=/Users/<username>/.local/bin/hpack ghci --test
  3. the language: GHC2021 entry in package.yaml is now included in the generated cabal file

@maerten maerten closed this as completed May 11, 2022
@maerten
Copy link
Author

maerten commented May 11, 2022

One additional question, can this setting be controlled via stack.yaml?

UPDATE: it seems that adding with-hpack: <path>/hpack to stack.yaml works

@mpilgrem
Copy link
Member

Yes, that is correct - see the documentation on the .yaml file: https://docs.haskellstack.org/en/stable/yaml_configuration/#with-hpack

@carlwr
Copy link

carlwr commented Jun 26, 2023

I still get GHC2010 in the .cabal file, although stack now seems to ship with hpack >= 0.35.0.

Any simple workaround? (I'd prefer to keep having the .cabal file auto-generated.)

I was also a bit confused about GHC and GHCi not defaulting to the same base languages:

stack ghci
λ> :show language
base language is: GHC2021
with the following modifiers:
λ>

Project was created with

stack new --resolver=lts-20.24 proj

Verifying hpack >= 0.35.0

stack --hpack-numeric-version
0.35.1

Still:

grep default-language proj.cabal
  default-language: Haskell2010
  default-language: Haskell2010
  default-language: Haskell2010

(All stack commands above were run in the project dir.)

Versions:

`stack exec -- which ghc` --version
The Glorious Glasgow Haskell Compilation System, version 9.2.7

stack --version | head -n 1
Version 2.9.3, Git revision d0e984f00034552aac7c67675d49ef0807c10c7b (dirty) (112 commits) aarch64

# macOS version:
sw_vers -productVersion
13.4

@mpilgrem
Copy link
Member

mpilgrem commented Jun 27, 2023

@LeuschkeTressa, if you specify language: GHC2021 in a package's package.yaml file, it should work - it does on my machine. EDIT: Stack's default template with stack new (new-template.hsfiles) does not specify a 'language' and, so, Hpack applies its default of Haskell2010.

@carlwr
Copy link

carlwr commented Jun 28, 2023

@LeuschkeTressa, if you specify language: GHC2021 in a package's package.yaml file, it should work

It does!

Thanks.

@carlwr
Copy link

carlwr commented Jun 29, 2023

For future readers:

Regarding (from my initial comment):

I was also a bit confused about GHC and GHCi not defaulting to the same base languages:

stack ghci
λ> :show language
base language is: GHC2021
with the following modifiers:
λ>

This inconsistency was previously reported as #5973.

b6d11f7 is intended to fix this. It was committed to release 2.11.1, which is a later release than what I am using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants