stack ghci does not load local module but ghci does - haskell-stack

This is similar to the question at
stack ghci not loading up local modules?
but not exactly the same.
I have a directory with the files Main.hs and Shapes.hs where Main.hs has a reference to the module Shapes.
If I run
ghci Main.hs
everything works fine. This is version 7.10.
But if I run, in version 8,
stack ghci
:load Main.hs
I get the error
[1 of 1] Compiling Main ( Main.hs, interpreted )
Main.hs:3:1: error:
Failed to load interface for ‘Shapes’
It is not a module in the current program, or in any known package.
Failed, modules loaded: none.
I tried the solution on the link
:load Shapes.hs Main.hs
but it still does not work. I get the error
[1 of 2] Compiling Shapes ( Shapes.hs, interpreted )
[2 of 2] Compiling Main ( Main.hs, interpreted )
Main.hs:1:1: error:
The IO action ‘main’ is not defined in module ‘Main’
Failed, modules loaded: Shapes.
I found the following which discusses this second matter:
How to avoid "‘main’ is not defined in module ‘Main’" when using syntastic
But if I were to put in
main :: IO ()
in the Main.hs file, I still get errors. If I were to additionally add the line
main = return ()
and have these two additional lines at the end, then it would load. But after loading it just exits main and I no longer have access to the functions in main.
I don't see any reason why I need to use any IO features when I import some other module. How do I, in version 8, load a local module without using IO?

I fixed my own problem. There was a line in Main.hs at the top called
module Main where
that I removed. Now it works if I load in stack ghci with
:l Main.hs Shapes.hs

Related

haskell stack can't find sdl_config? windows 10

I'm trying to install sdl model into haskell. I have this problem and I don't know where to put the sdl_config and how to set it up.
I have tried mutiple ways to get sdl_config working, such as building it with Code::blocks but I never seem to get it to work.
[1 of 2] Compiling Main ( C:\Users\name\AppData\Local\Temp\stack14648\SDL-0.6.7.0\Setup.lhs, C:\Users\name\AppData\Local\Temp\stack14648\SDL-0.6.7.0\.stack-work\dist\e626a42b\setup\Main.o )
[2 of 2] Compiling StackSetupShim ( C:\sr\setup-exe-src\setup-shim-Z6RU0evB.hs, C:\Users\name\AppData\Local\Temp\stack14648\SDL-0.6.7.0\.stack-work\dist\e626a42b\setup\StackSetupShim.o )
Linking C:\Users\name\AppData\Local\Temp\stack14648\SDL-0.6.7.0\.stack-work\dist\e626a42b\setup\setup.exe ...
Configuring SDL-0.6.7.0...
configure: WARNING: unrecognized options: --with-compiler
configure: loading site script /usr/local/etc/config.site
checking for sdl-config... no
checking for sdl11-config... no
configure: error: *** SDL not found! Get SDL from www.libsdl.org.
If you already installed it, check it's in the path. If problem remains,
please send a mail to the address that appears in ./configure --version
indicating your platform, the version of configure script and the problem.
I want haskell stack to be able to install SDL model into haskell without error.

Haskell Stack doesnt work correctly on OSX Sierra

I can't get haskell's stack to work on my Mac.
I installed haskell by:
brew cask install haskell-platform
Which is specified here: https://www.haskell.org/platform/mac.html#osx-homebrewcask
I've also tried installing via the downloadable package at the same site.
I do the following commands:
stack new my-project
cd my-project
stack setup
stack build
stack exec my-project-exe
Per the documentation here:
https://docs.haskellstack.org/en/stable/README/#quick-start-guide
And I immediately see this:
[1] 43017 killed stack exec my-project-exe
I've also tried many other ways of installing haskell. I've actually been able to get something compiled and executed just using cabal, but I can't then get hlint, hindent, or ghc-mod to work, they all return a similar message to the one above. I'd love to be able to work with HaskForce in IntelliJ on my Mac, but I've never had luck getting haskell to work.
System Specs
macOS 10.12.6 (16G29) (Sierra)
Fresh uninstall/reinstall of XCode (accepted terms)
brew as package manager
Here's a gif of what happens as well: https://imgur.com/gallery/afYym7m
UPDATE
I blew away all stuff related to ghc, stack, and cabal and then installed this way
https://haskell-lang.org/get-started
Writing the little HelloWorld.hs script worked fine and showed Hello, World
However, doing
stack new someproj
cd someproj
stack build
Resulted in this:
➜ someproj stack build
[1 of 2] Compiling Main ( /Users/trevord2/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /Users/trevord2/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim ( /Users/trevord2/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/trevord2/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /Users/trevord2/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 ...
someproj-0.1.0.0: configure (lib + exe)
Configuring someproj-0.1.0.0...
someproj-0.1.0.0: build (lib + exe)
Preprocessing library someproj-0.1.0.0...
[1 of 1] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'someproj-exe' for someproj-0.1.0.0...
[1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/someproj-exe/someproj-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/someproj-exe/someproj-exe ...
ld: warning: ignoring file /Users/trevord2/someproj/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a, file was built for archive which is not the architecture being linked (x86_64): /Users/trevord2/someproj/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/libHSsomeproj-0.1.0.0-6corWoTDCA69pE1sqNF8Id.a
Undefined symbols for architecture x86_64:
"_someprojzm0zi1zi0zi0zm6corWoTDCA69pE1sqNF8Id_Lib_someFunc1_closure", referenced from:
_Main_main1_info in Main.o
_S39Z_srt in Main.o
"_someprojzm0zi1zi0zi0zm6corWoTDCA69pE1sqNF8Id_Lib_someFunc1_info", referenced from:
_Main_main_info in Main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
-- While building package someproj-0.1.0.0 using:
/Users/trevord2/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:someproj exe:someproj-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Which I've seen before and was actually one of my initial problems
UPDATE 2: Created GitHub Issue
Here's the issue: https://github.com/commercialhaskell/stack/issues/3487
After talking with folks on #haskell IRC they recommended I create an issue as this is very peculiar behaviour from what I understand. I'll try make sure whatever we find out here is pushed up there too.

Compiling c-extension from cython, "bad reloc address 0x0 in section `.data'" , "Python.h: No such file or directory"

I have written a code in MATLAB for a project in school (Pott's model in 3D for q = 3 states), that took to long to simulate, and rewrote my code in Python. The code was marginally faster but not fast enough, so I was thinking I could speed it up converting my Python file to C using Cython. Now before you ask, I know that Matlab has an inbuilt app for c-conversion of Matlab code, but I don't get it to work.
I am using:
- Windows 10
- Python 3.6
- Cython 0.25.2
- MinGW as gcc
According to Cython basic tutorial
I need a setup.py file, so I have made one in the same folder as my main.py file and it looks like this:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("main.pyx")
)
From the same tutorial it says to save the .py file to .pyx and then write this line in Anaconda prompt:
python setup.py build_ext --inplace
Doing this, a "main.c"-file is produced, and it is at this point where it gets ugly. I am a real novice to the language c, but I try to compile this c-file in CMD to get an executable to run my program.
I first tried to type this in CMD:
gcc main.c
Which gave me the message:
main.c:11:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
From this part, I also included the path to where python.h amongst other necessary files were (I also tried to include the path to my system variable PATH, hoping to not have to type in the path every time I try to compile, without succeeding... )
So this is what I am typing now instead:
C:\Users\burke\OneDrive\Spyder\F7035T>gcc -I C:\Users\burke\AppData\Local\Programs\Python\Python36-32\include main.c
From that, the output from the CMD where hundred of lines of undefined references, so I only include the last rows, so you get the picture of it:
C:\Users\burke\AppData\Local\Temp\cc5gCfUu.o:main.c:(.text+0x32469): undefined reference to `__imp__Py_NoneStruct'
C:\Users\burke\AppData\Local\Temp\cc5gCfUu.o:main.c:(.text+0x32489): undefined reference to `__imp_PyObject_IsTrue'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\burke\AppData\Local\Temp\cc5gCfUu.o: bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status
At this point, I no longer know what to do. I have tried to google it without any good result. I hope someone can help me with this problem. Sorry for my English, I'm from Sweden.
/Johan

Calling dynamic libraries from c-sources fails in ghci

I have some C functions from a dynamic library (just zlibVersion here) that I'd like to call from bundled C code in a cabal package. Here I call it both directly as a foreign import and indirectly through the bundled C code to show that the latter crashes ghci, even after the former succeeds.
Main.hs:
module Main (main) where
import Foreign.C.String (CString, peekCString)
foreign import ccall "foreign_test" foreignTest :: IO ()
foreign import ccall "zlibVersion" zlibVersion :: IO CString
main :: IO ()
main = do
zlibVersion >>= peekCString >>= putStrLn
foreignTest
foreign_test.c:
#include <stdio.h>
#include <zlib.h>
void foreign_test() {
puts(zlibVersion());
}
It works fine from a compiled binary:
$ cabal build
$ dist/build/cabal-extra-libs-test/cabal-extra-libs-test
1.2.5
1.2.5
But the indirect call crashes ghci:
$ cabal repl
Preprocessing executable 'cabal-extra-libs-test' for
cabal-extra-libs-test-0.1.0.0...
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Main.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
1.2.5
dyld: lazy symbol binding failed: Symbol not found: _zlibVersion
Referenced from: /var/folders/pz/920gzhqn01q8d6vjkvy1yvdr0000gn/T/ghc6850_0/libghc_1.dylib
Expected in: flat namespace
dyld: Symbol not found: _zlibVersion
Referenced from: /var/folders/pz/920gzhqn01q8d6vjkvy1yvdr0000gn/T/ghc6850_0/libghc_1.dylib
Expected in: flat namespace
cabal-extra-libs-test.cabal:
name: cabal-extra-libs-test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
executable cabal-extra-libs-test
default-language: Haskell2010
main-is: Main.hs
build-depends: base
c-sources: foreign_test.c
extra-libraries: z
GHC is 7.10.3 with cabal-install 1.24.0.0 on OS X 10.11.5. Building with stack and stack ghci produces the same crash.
That's peculiar.. I don't know much about OSX but dyld: lazy symbol binding failed: Symbol not found: _zlibVersion gives the impression It thinks OSX is an underscore platform (e.g. one where C functions are mangled with an _).
Is this a standard GHC build? and can you try with 8.0.1? lots has changed in the linker.

Haskell: http-wget hangs my program in windows

I've tried this on two computers. Here are my steps:
install wget on cygwin
cabal install http-wget
upgrade my PATH environment variable to include C:\cygwin\bin
open WinGHCi and type this:
From prompt:
GHCi, version 7.4.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.
Prelude> :m + Network.HTTP.Wget
Prelude Network.HTTP.Wget> wget "http://www.google.com" [] []
Loading package bytestring-0.9.2.1 ... linking ... done.
Loading package Win32-2.2.2.0 ... linking ... done.
Loading package filepath-1.3.0.0 ... linking ... done.
Loading package old-locale-1.0.0.4 ... linking ... done.
Loading package old-time-1.1.0.0 ... linking ... done.
Loading package directory-1.1.0.2 ... linking ... done.
Loading package process-1.1.0.1 ... linking ... done.
Loading package failure-0.1.2 ... linking ... done.
Loading package transformers-0.2.2.0 ... linking ... done.
Loading package http-wget-0.6.2.3 ... linking ... done.
Nothing else happens after this line. The command doesn't complete. It just hangs forever. I'm very new to Haskell and don't know how to debug this issue.
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.2
I've tried the wget command in the cygwin prompt and it works as expected.
This works from WinGHCi:
let getGoogle = do (_, Just hout, _, _) <- createProcess (proc "wget" ["-q", "www.google.com", "-O", "-"]){ std_out = CreatePipe }; hGetContents hout
I got that from IRC from a gentleman named mcstar

Resources