Structured Haskell Mode fails to install - haskell

I am trying to update my structured haskell mode using the cabal install command. Unfortunately, it's failing
obelix:~ rk$ cabal install structured-haskell-mode
Warning: The install command is a part of the legacy v1 style of cabal usage.
Please switch to using either the new project style and the new-install
command or the legacy v1-install alias as new-style projects will become the
default in the next version of cabal-install. Please file a bug if you cannot
replicate a working v1- use case with the new-style commands.
For more information, see: https://wiki.haskell.org/Cabal/NewBuild
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Resolving dependencies...
Starting structured-haskell-mode-1.1.0
Building structured-haskell-mode-1.1.0
Failed to install structured-haskell-mode-1.1.0
Build log ( /Users/rk/.cabal/logs/ghc-8.4.3/structured-haskell-mode-1.1.0-BtZnu5PUgZA64b8d6lKBIV.log ):
cabal: Entering directory '/var/folders/m7/cw4w1yc11pv_t25pmlyqc4qm0000gn/T/cabal-tmp-1494/structured-haskell-mode-1.1.0'
Configuring structured-haskell-mode-1.1.0...
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Preprocessing executable 'structured-haskell-mode' for structured-haskell-mode-1.1.0..
Building executable 'structured-haskell-mode' for structured-haskell-mode-1.1.0..
[1 of 1] Compiling Main ( src/Main.hs, dist/build/structured-haskell-mode/structured-haskell-mode-tmp/Main.o )
src/Main.hs:165:18: error:
• The constructor ‘Deriving’ should have 3 arguments, but has been given 2
• In the pattern: Deriving _ ds#(_ : _)
In the pattern: Just (Deriving _ ds#(_ : _))
In a case alternative:
Just (Deriving _ ds#(_ : _))
-> [spanHSE
(show "InstHeads")
"InstHeads"
(SrcSpan
(srcSpanFilename start)
(srcSpanStartLine start)
(srcSpanStartColumn start)
(srcSpanEndLine end)
(srcSpanEndColumn end)) |
Just (IRule _ _ _ (IHCon (SrcSpanInfo start _) _)) <- [listToMaybe
ds],
Just (IRule _ _ _ (IHCon (SrcSpanInfo end _) _)) <- [listToMaybe
(reverse ds)]]
|
165 | Just (Deriving _ ds#(_:_)) ->
| ^^^^^^^^^^^^^^^^^^^
cabal: Leaving directory '/var/folders/m7/cw4w1yc11pv_t25pmlyqc4qm0000gn/T/cabal-tmp-1494/structured-haskell-mode-1.1.0'
cabal: Error: some packages failed to install:
structured-haskell-mode-1.1.0-BtZnu5PUgZA64b8d6lKBIV failed during the
building phase. The exception was:
ExitFailure 1
It seems that it's calling the Deriving constructor with the wrong number of arguments. Any suggestions for a quick fix?

Related

How to override `doctest` to use my `ghc`?

I have problem using doctest with QuickCheck on NixOS
-- code.hs
--
-- $setup
-- >>> import Test.QuickCheck
--
-- |
-- This test will pass
-- >>> 1 + 1
-- 2
--
-- This test use QuickCheck
-- prob> \xs -> reverse xs = reverse . id $ xs
--
-- The last test will fail to ensure doctest was running
-- >>> 1 == 0
-- True
--
main :: IO ()
main = pure ()
The default haskellPackages.doctest doesn't include QuickCheck
$ nix-shell -p haskellPackages.doctest --run 'doctest code.hs'
code.hs:4: failure in expression `import Test.QuickCheck'
expected:
but got:
<no location info>: error:
Could not find module ‘Test.QuickCheck’
It is not a module in the current program, or in any known package.
Examples: 3 Tried: 1 Errors: 0 Failures: 1
so I try to make an overrride version as mydoctest
# ~/.config/nixpkgs/overlays/doctest.nix
self: super:
with super.haskellPackages;
let
myghc = ghcWithPackages (p: with p;
[
QuickCheck
]);
in
{
mydoctest = doctest.override {
ghc = myghc;
};
}
It still can't find QuickCheck
$ nix-shell -p mydoctest --run 'doctest code.hs'
code.hs:4: failure in expression `import Test.QuickCheck'
expected:
but got:
<no location info>: error:
Could not find module ‘Test.QuickCheck’
It is not a module in the current program, or in any known package.
Examples: 3 Tried: 1 Errors: 0 Failures: 1
but it work if I call it via ghc
$ nix-shell -p mydoctest --run 'ghc -e ":!doctest code.hs"'
code.hs:15: failure in expression `1 == 0'
expected: True
but got: False
Examples: 3 Tried: 3 Errors: 0 Failures: 1
myghc is there but didn't use by mydoctest
$ nix-shell -p mydoctest --run 'doctest --version'
doctest version 0.16.0
using version 8.4.3 of the GHC API
using /nix/store/g1dj8c6h6g8rbb8cv9bgmp1h2f3bxk1l-ghc-8.4.3-with-packages/bin/ghc
$ nix-shell -p mydoctest --run 'which ghc'
/nix/store/qj3vnm903p77nxiraxqxm9b8gbz5rpia-ghc-8.4.3-with-packages/bin/ghc
How can I make doctest to use my override ghc ?
Haskell derivations are not suitable as nix-shell environments by themselves.
The Nixpkgs manual recommends creating a derivation for the purpose of a nix-shell only, using a ghcWithPackages invocation as a dependency.
If the file you're trying to run is part of a haskell package, you can use cabal2nix to do most of the work for you.
I recommend the latter, because it does not pollute your user-wide state (whether profile or user-specific overlay), it is easier to share with others and provides structure that is sufficient to scale from toy example to a valuable package.
I had the same problem trying to get my nix/haskell dev environment set up and found a solution in this reddit post. To get doctest to use a specific version of ghc you can set the environment variable NIX_GHC:
$ doctest --version
doctest version 0.16.3
using version 8.10.3 of the GHC API
using /nix/store/9bm9bs9c4zpl17zdk1d0azid44x3h99b-ghc-8.10.3/bin/ghc-8.10.3
$ export NIX_GHC=/nix/store/zvx9dmfqaa8wibygkbibg4kl98pfj9qv-ghc-8.10.3-with-packages/bin/ghc
$ doctest --version
doctest version 0.16.3
using version 8.10.3 of the GHC API
using /nix/store/zvx9dmfqaa8wibygkbibg4kl98pfj9qv-ghc-8.10.3-with-packages/bin/ghc

Could not find module ‘Criterion.Main’

I have copied the following code from criterion tutorial:
import Criterion.Main
-- The function we're benchmarking.
fib m | m < 0 = error "negative!"
| otherwise = go m
where
go 0 = 0
go 1 = 1
go n = go (n-1) + go (n-2)
-- Our benchmark harness.
main = defaultMain [
bgroup "fib" [ bench "1" $ whnf fib 1
, bench "5" $ whnf fib 5
, bench "9" $ whnf fib 9
, bench "11" $ whnf fib 11
]
]
I am getting the following error:
fiber.hs:1:1: error:
Could not find module ‘Criterion.Main’
Use -v to see a list of the files searched for.
|
1 | import Criterion.Main
| ^^^^^^^^^^^^^^^^^^^^^
The GHC version I am using is 8.4.2 and cabal version is 2.2.0.0.
I tried to install the criterion package by:
cabal update
Downloading the latest package list from hackage.haskell.org
To revert to previous state run: cabal update --index-state='2018-06-
01T04:23:08Z'
cabal install -j --disable-tests criterion
clang: warning: argument unused during compilation: '-nopie' [-Wunused-
command-line-argument]
.
.
.
.
cabal: Error: some packages failed to install:
abstract-deque-0.3-IvBVpgU2tvq3eILHsBTjFR failed during the building
phase.
The exception was:
ExitFailure 1
aeson-1.3.1.1-J9Jy9Bz77dxJho59OWZvUt depends on aeson-1.3.1.1 which
failed to install.
attoparsec-0.13.2.2-5fvnJr9WRPCJj7fMCLKoI7 depends on attoparsec-
0.13.2.2
which failed to install.
cassava-0.5.1.0-CNxiRQP2h44BSkY7PLw3nv depends on cassava-0.5.1.0 which
failed
to install.
criterion-1.4.1.0-1CDqJgx5SYk1Xphp8S6hvK depends on criterion-1.4.1.0
which failed to install.
microstache-1.0.1.1-DUzquwnO02sC17piNr03EI depends on microstache-
1.0.1.1 which failed to install.
monad-par-0.3.4.8-5Qx7yEAZEkjJbqZykcUjIa depends on monad-par-0.3.4.8
which failed to install.
monad-par-extras-0.3.3-755mClpwIBoBMORFcN7gCY failed during the
building phase. The exception was:
ExitFailure 1
scientific-0.3.6.2-65wDZeAE9ZIBkaesoEq4I0 failed during the building
phase.
The exception was:
ExitFailure 1
statistics-0.14.0.2-GHJ1OiovyXP1FEjV1emzr8 depends on statistics-
0.14.0.2 which failed to install.
text-short-0.1.2-JRY9FeZhxkoAZrj3rm5IJZ failed during the building
phase. The exception was:
ExitFailure 1
uuid-types-1.0.3-tE9Bfk2PgXDUPgbtamBdI failed during the building
phase. The exception was:
ExitFailure 1
One approach would be to use the Stack script interpreter to run this. In order to do so, you would first install Stack, then add the script interpreter bits to the top of your file, e.g.:
#!/usr/bin/env stack
-- stack --resolver lts-11.10 script --optimize
import Criterion.Main
-- The function we're benchmarking.
fib m | m < 0 = error "negative!"
| otherwise = go m
where
go 0 = 0
go 1 = 1
go n = go (n-1) + go (n-2)
-- Our benchmark harness.
main = defaultMain [
bgroup "fib" [ bench "1" $ whnf fib 1
, bench "5" $ whnf fib 5
, bench "9" $ whnf fib 9
, bench "11" $ whnf fib 11
]
]
Note that I added the --optimize option on the second line to ensure that Stack would compile your code with optimizations on, instead of the default of using runghc.
And finally run the file with stack fiber.hs (or whatever you called the file).

How to resolve issue with building stream-fusion

I'm trying to bring in the stream-fusion library into my project. I am using Stack (LTS 5.16). I added the stream-fusion-0.1.2.5 version to my project's cabal file and also as an extra-dependency in my stack.yaml.
However, when I try to build the project I now get the following:
stream-fusion-0.1.2.5: configure
stream-fusion-0.1.2.5: build
-- While building package stream-fusion-0.1.2.5 using:
/Users/me/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /Users/me/Haskell/hqfl/.stack-work/logs/stream-fusion-0.1.2.5.log
Configuring stream-fusion-0.1.2.5...
Building stream-fusion-0.1.2.5...
Preprocessing library stream-fusion-0.1.2.5...
[1 of 3] Compiling Data.Stream ( Data/Stream.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Data/Stream.o )
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/Stream.hs:591:5: Warning:
Pattern match(es) are non-exhaustive
In an equation for ‘next’:
Patterns not matched: (_ :!: (Just (L _))) :!: S2
[2 of 3] Compiling Data.List.Stream ( Data/List/Stream.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Data/List/Stream.o )
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:235:1: Warning:
The import of ‘seq, Int’ from module ‘Prelude’ is redundant
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:1703:10: Warning: Tab character
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:2496:1: Warning:
Rule "genericSplitAt -> fusible" may never fire
because ‘genericSplitAt’ might inline first
Probable fix: add an INLINE[n] or NOINLINE[n] pragma on ‘genericSplitAt’
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:2504:1: Warning:
Rule "genericSplitAt -> splitAt/Int" may never fire
because ‘genericSplitAt’ might inline first
Probable fix: add an INLINE[n] or NOINLINE[n] pragma on ‘genericSplitAt’
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:2516:1: Warning:
Rule "genericReplicate -> replicate/Int" may never fire
because ‘genericReplicate’ might inline first
Probable fix: add an INLINE[n] or NOINLINE[n] pragma on ‘genericReplicate’
[3 of 3] Compiling Control.Monad.Stream ( Control/Monad/Stream.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Control/Monad/Stream.o )
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Control/Monad/Stream.hs:136:10:
Ambiguous occurrence ‘MonadPlus’
It could refer to either ‘Control.Monad.Stream.MonadPlus’,
defined at Control/Monad/Stream.hs:124:1
or ‘GHC.Base.MonadPlus’,
imported from ‘GHC.Base’ at Control/Monad/Stream.hs:80:1-15
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Control/Monad/Stream.hs:140:10:
Ambiguous occurrence ‘MonadPlus’
It could refer to either ‘Control.Monad.Stream.MonadPlus’,
defined at Control/Monad/Stream.hs:124:1
or ‘GHC.Base.MonadPlus’,
imported from ‘GHC.Base’ at Control/Monad/Stream.hs:80:1-15
How can I resolve the ambiguity here?
you need to change the following imports in Control.Monad.Stream (line 80)
- import GHC.Base
+ import GHC.Base hiding ( MonadPlus
+ , (=<<)
+ , ap
+ , join
+ , liftM
+ , liftM2
+ , liftM3
+ , liftM4
+ , liftM5
+ , mapM
+ , mplus
+ , mzero
+ , sequence
+ , when
+ )
Then it compiles - I don't know wether it will work as expected, this library is quite old (3 years as of now) and the tested-with section in the cabal file says 7.6.1. - I recommend using benchmarks to ensure that the benefits you hope to get from this library are real. I would guess that a lot of the ideas of this library have made it into base by now.
Could you leave a comment after you have done these benchmarks I would really be interested in them.

GHC Linker error (stack)

I'm somewhat of a beginner in Haskell and I'm trying out stack to build an application.
However, stack build gives me linker errors when executed:
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/sim-exe/sim-exe ...
[...]/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/libHSsim-0.1.0.0-EmdGqYS9bXF9VefempSPEG.a(Lib.o):(.text+0x98f5): undefined reference to `simzuEmdGqYS9bXF9VefempSPEG_Linter_lint_info'
[...]/.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/libHSsim-0.1.0.0-EmdGqYS9bXF9VefempSPEG.a(Lib.o):(.data+0x5f0): undefined reference to `simzuEmdGqYS9bXF9VefempSPEG_Linter_lint_closure'
collect2: error: ld returned 1 exit status
Looking at the labels tells me it's related to a closure in this function:
lint :: String -> [LintError]
lint source = let
handleParseError :: ParseError -> [LintError]
handleParseError e = [LintError (fromSourcePos $ errorPos e) $ format e]
in
case parseSim source of
(Left error) -> handleParseError error
(Right prog) -> lintProgram prog
But there's not really a closure in there? If I replace the implementation of lint with
lint _ = []
it compiles fine.
I can execute stack ghci and play around with the full lint implementation just fine. Why does it fail to link?
As yuras correctly pointed out, adding the module under exposed-modules in the cabal file resolves the issue.

Why does ghci not use relative paths?

If I have a project structured like this:
project/
src/
Foo.hs
Bar.hs
With files Foo.hs:
module Foo where
foo :: String
foo = "foo"
and Bar.hs:
module Bar where
import Foo
bar :: String
bar = foo ++ "bar"
If my current directory is src, and I enter ghci and run :l Bar.hs, I get the expected output:
[1 of 2] Compiling Foo ( Foo.hs, interpreted )
[2 of 2] Compiling Bar ( Bar.hs, interpreted )
Ok, modules loaded: Bar, Foo.
But if I move up to the project directory (which is where I'd prefer to stay and run vim/ghci/whatever), and try :l src/Bar.hs, I get:
src/Bar.hs:3:8:
Could not find module ‘Foo’
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Why does ghc not search for Foo in the same directory as Bar? Can I make it do so? And can I propagate that change up to ghc-mod and then to ghcmod.vim? Because I get errors about can't find module when I'm running my syntax checker or ghc-mod type checker in vim.
I'm running ghc 7.10.1.
The flag you're looking for is -i<dir>:
% ghci --help
Usage:
ghci [command-line-options-and-input-files]
...
In addition, ghci accepts most of the command-line options that plain
GHC does. Some of the options that are commonly used are:
-i<dir> Search for imported modules in the directory <dir>.
For example
% ls src
Bar.hs Foo.hs
% ghci -isrc
GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ :l Foo
[1 of 1] Compiling Foo ( src/Foo.hs, interpreted )
Ok, modules loaded: Foo.
λ :l Bar
[1 of 2] Compiling Foo ( src/Foo.hs, interpreted )
[2 of 2] Compiling Bar ( src/Bar.hs, interpreted )
Ok, modules loaded: Foo, Bar.
You can also pass ghc-mod the -i<dir> flag from within ghcmod.vim
If you'd like to give GHC options, set g:ghcmod_ghc_options.
let g:ghcmod_ghc_options = ['-idir1', '-idir2']
Also, there's buffer-local version b:ghcmod_ghc_options.
autocmd BufRead,BufNewFile ~/.xmonad/* call s:add_xmonad_path()
function! s:add_xmonad_path()
if !exists('b:ghcmod_ghc_options')
let b:ghcmod_ghc_options = []
endif
call add(b:ghcmod_ghc_options, '-i' . expand('~/.xmonad/lib'))
endfunction

Resources