Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global configuration for GHC build flags

Tags:

haskell

ghc

Is there a place I can configure some default flags for GHC to use? I'd like, i.e., GHC to always assume I want the -fwarn-incomplete-patterns flag. This page gives a list of useful flags and indicates that some of them are on by default, but again, I'd like to change the defaults for my system.

I'm currently working on OS X, but I use Debian, Arch Linux, and Windows 8.1 at home, so a solution for any platform will help.

like image 761
Amazingant Avatar asked Apr 22 '14 16:04

Amazingant


3 Answers

Apart from aliasing the shell command ghc to ghc -fwarn-incomplete-patterns, I don't think there's a way to do it globally or whether it would be advisable to do globally since it would probably generate an enormous amount of warnings when compiling external libraries with cabal. Probably best to do this one project at a time or just with GHCi:

There's a ghc-options section in any cabal file for a project.

library
  ...

  ghc-options:        
    -fwarn-tabs
    -fwarn-missing-local-sigs
    -fwarn-incomplete-patterns
    -fwarn-incomplete-uni-patterns

For global GHCi, you can add the following line to your ~/.ghc/ghci.conf

:set -fwarn-incomplete-uni-patterns 
like image 186
Stephen Diehl Avatar answered Sep 28 '22 10:09

Stephen Diehl


Add ghc-options: -fwarn-incomplete-patterns to the program-default-options section of your ~/.cabal/config:

[...]

program-default-options
    ...
    ghc-options: -fwarn-incomplete-patterns
    ...

This only works with Cabalised projects (i.e. when you use cabal build/install/[...] instead of running ghc --make SomeFile.hs manually) and requires a fairly recent cabal-install (>= 1.18).

like image 35
Mikhail Glushenkov Avatar answered Sep 28 '22 11:09

Mikhail Glushenkov


Just because this will be useful for people who come here:

On Gentoo, you can set options for all Cabal packages, (which is pretty much all of them) globally, in /etc/portage/make.conf, with the variable CABAL_EXTRA_BUILD_FLAGS. So in your case, that would be

CABAL_EXTRA_BUILD_FLAGS="--ghc-option=-fwarn-incomplete-patterns"

, and here is a more advanced example

CABAL_EXTRA_BUILD_FLAGS="--ghc-option=+RTS --ghc-option=-M1G --ghc-option=-RTS"

to limit memory usage to 1GB (and exit otherwise).

I think there’s a similar solution for Arch and Debian, but since OS X is a consumer OS, I don’t know.

like image 29
Evi1M4chine Avatar answered Sep 28 '22 09:09

Evi1M4chine