GHC Linker error (stack) - haskell

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.

Related

Nested allocatable components [duplicate]

Consider the following code:
subroutine tao_show_this ()
implicit none
type b_struct
integer, pointer :: good_user => null()
end type
type a_struct
type (b_struct), allocatable :: value_ptr(:)
end type
type (a_struct) a
a = a_struct()
end subroutine
Compiling with gfortran 5 or 7 gives:
gfortran -c test.f90
test.f90:4:13:
type b_struct
1
Error: The rank of the element in the structure constructor at (1) does not match that of the component (0/1)
This code compiles fine with ifort. Is this a gfortran bug or is there something wrong with my code?
For a default structure constructor, being able to omit the value for an allocatable component is a feature introduced in Fortran 2008.
gfortran does not currently support this feature ("Unimplemented features").
To leave the component not allocated while still giving a value to the constructor one references null:
a = a_struct(NULL())
As DavidS comments, this exists as a reported bug.

Structured Haskell Mode fails to install

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?

Haskell/GHC 7.10.1/Leksah : What is the meaning of this Warning: "name ... found in source file but was not in scope"

I am using the Leksah IDE 0.15.0.1 and I get a warning when compiling the example package: "name ... found in source file but was not in scope".
What is the meaning of this Warning ?
I googled for this text but found noting enlightening.
The problem probably lies within the lines
testMain = do
allPass <- $quickCheckAll
unless allPass exitFailure
According to the QuickCheck documentation, in order to utilize quickCheckAll, the IO action that performs $quickCheckAll must have return [] before its definition.
To use quickCheckAll, add a definition to your module along the lines of
return []
runTests = $quickCheckAll
and then execute runTests.
So applying it to your testMain definition, it would end up being
return []
testMain = do
allPass <- $quickCheckAll
unless allPass exitFailure
The documentation also provides an explanation for such need:
Note: the bizarre return [] in the example above is needed on GHC 7.8 and > later; without it, quickCheckAll will not be able to find any of the
properties. For the curious, the return [] is a Template Haskell
splice that makes GHC insert the empty list of declarations at that
point in the program; GHC typechecks everything before the return []
before it starts on the rest of the module, which means that the later
call to quickCheckAll can see everything that was defined before the
return []. Yikes!

Why does GHC only warn on partial implemented classes, and not error?

I think the title is already self explanatory, but here's an example anyway to show my point:
class Foo a where
someFunction :: a -> a -> Bool
instance Foo Bool
When I compile this the compiler gives a warning:
Warning:
No explicit method or default declaration for `someFunction'
in the instance declaration for `Foo Bool'
Calling the function will now result in a runtime error. Why is this a warning, and not a compile-time error? And is there any way to make this a compile-time error instead?
The GHC documentation provides an example where a warning is sufficient:
-fwarn-missing-methods:
This option is on by default, and warns you whenever an instance declaration is missing one or more methods, and the corresponding class declaration has no default declaration for them.
The warning is suppressed if the method name begins with an underscore.
Here's an example where this is useful:
class C a where
_simpleFn :: a -> String
complexFn :: a -> a -> String
complexFn x y = ... _simpleFn ...
The idea is that: (a) users of the class will only call complexFn; never _simpleFn; and (b) instance declarations can define either complexFn or _simpleFn.
The MINIMAL pragma can be used to change which combination of methods will be required for instances of a particular class. See Section 7.20.5, “MINIMAL pragma”.
That's the reason missing methods don't result in an error, but a warning. If you want to make warnings fatal, use -Werror. Since there is no -ferr-missing-methods, -Werror is the only way to make -fwarn-missing-methods a compiler error.

Haskell N00b: IntelliJ giving two errors

As a junior CS major I'm taking it upon myself to try to cram in learning Haskell over fall breaks (for myself...not sure why I'm torturing myself). I downloaded IntelliJ and installed the official Haskell plugin from Jetbrains.
I'm following instructions from "Learn You a Haskell for Great Good!"
While compiling this code:
test = putStrLn "Hello World!"
I get this error:
Information:Compilation completed with 2 errors and 1 warning in 2 sec
Information:2 errors
Information:1 warning
Error:cabal: build errors.
Warning:ghc: warning: control reaches end of non-void function [-Wreturn-type]
int foo() {}
^
/Users/<USER_NAME>/Documents/Dropbox/Developer/IntelliJ/src/Main.hs
Error:(1, 1) ghc: The function `main' is not defined in module `Main'
I don't have this issue when using a text editor and Terminal...however I love IDE's (sorry VIM guys). Also, I'm running OS X 10.9 which, from my research, has been known to cause issues.
You are missing a main function, just like the error tells you. Just have:
main :: IO ()
main = putStrLn "Hello World!"
or:
test :: IO ()
test = putStrLn "Hello World!"
main :: IO ()
main = test
If it's still giving you problems, then at the very beginning of the file just add:
module Main where

Resources