Haskell: http-wget hangs my program in windows - 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

Related

stack ghci does not load local module but ghci does

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

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.

Can't compile a simple hello world using GHC 7.8rc2 and Windows 7 (or install packages with cabal)

I can't compile a simple hello world or install packages with cabal install when using ghc 7.8, cabal 1.18.1.3 and cabal-install 1.18.0.2.
When doing a cabal install stm (or any other package) from a command prompt Windows shows a "ghc.exe has stopped working" window, and the output is:
Reading available packages...
Choosing modular solver.
Resolving dependencies...
Ready to install stm-2.4.2
Extracting
Waiting for install task to finish...
C:\Users\%USER%\AppData\Roaming\cabal\packages\hackage.haskell.org\stm\2.4.2\stm-2.4.2.tar.gz
to C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556...
Updating stm.cabal with the latest revision from the index.
Configuring stm-2.4.2...
creating C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist\setup
creating C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist
creating C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist\setup
"c:\ghc-7.8.0\bin\ghc.exe" "--make" "-odir" "C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist\setup" "-hidir" "C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist\setup" "-i" "-iC:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2" "-package-id" "Cabal-1.18.1.3-ac8664a5c71d605f2a4a8e21170969e0" "C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist\setup\setup.hs" "-o" "C:\Users\%USER%\AppData\Local\Temp\stm-2.4.2-6556\stm-2.4.2\dist\setup\setup.exe"
Failed to install stm-2.4.2
Last 10 lines of the build log ( C:\Users\%USER%\AppData\Roaming\cabal\logs\stm-2.4.2.log ):
World file is already up to date.
cabal.exe: Error: some packages failed to install:
stm-2.4.2 failed during the configure step. The exception was:
user error
I installed(?) GHC 7.8 and cabal-install with the following steps
Downloaded GHC 7.8 RC2 (http://www.haskell.org/ghc/dist/7.8.1-rc2/ghc-7.8.0.20140228-i386-unknown-mingw32.tar.bz2)
Extracted the contents of the tar to folder $GHC$
Added $GHC$\bin and $GHC$\mingw\bing folder to the PATH.
Downloaded prebuilt cabal-install (
http://www.haskell.org/cabal/release/cabal-install-1.18.0.2/cabal.exe)
Copied cabal.exe to $GHC$\bin so it's in the path
Run cabal update
Run cabal install stm (or any other package)
Before doing all this, I uninstalled my previous Haskell Platform, deleted folders cabal and ghc from %USER%\AppData\Roaming, and other haskell stuff from the Program Files folder.
I am not sure if GHC needed any additional installation steps
I need GHC 7.8 because I want to try out GHCJS.
PS:
I also added LANG=C to my env variables so that compiling does not throw a UTF-8 encoding error.
cabal --version shows:
cabal-install version 1.18.0.2
using version 1.18.1 of the Cabal library
Which seems to be ok except that the cabal library shows up as 1.18.1 instead of 1.18.1.3, but i'm not sure that's an error.
ghc-pkg list shows:
c:/ghc-7.8.0\lib\package.conf.d:
Cabal-1.18.1.3
Win32-2.3.0.1
array-0.5.0.0
base-4.7.0.0
bin-package-db-0.0.0.0
binary-0.7.1.0
rts-1.0
bytestring-0.10.4.0
containers-0.5.4.0
deepseq-1.3.0.2
directory-1.2.0.2
filepath-1.3.0.2
(ghc-7.8.0.20140228)
ghc-prim-0.3.1.0
(haskell2010-1.1.1.1)
(haskell98-2.0.0.3)
hoopl-3.10.0.0
hpc-0.6.0.1
integer-gmp-0.5.1.0
old-locale-1.0.0.6
old-time-1.1.0.2
pretty-1.1.1.1
process-1.2.0.0
template-haskell-2.9.0.0
time-1.4.1
transformers-0.3.0.0
** EDIT **: Trying to compile stm manually by going into its folder and running ghc generates the same error window and gives the output:
EDIT 2: Actually, I can't even compile a simple hello world with ghc helloworld.hs:
main = putStrLn "Hello, World!"
Compiling with "-v3" gives the following (uninformative) output:
Glasgow Haskell Compiler, Version 7.8.0.20140228, stage 2 booted by GHC version 7.6.3
Using binary package database: C:\ghc-7.8.0\lib\package.conf.d\package.cache
wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-ce20d91f79b43ede95508e8cfd2188b0
wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-67cd00feecdc491a633c46b0f7652b46
wired-in package base mapped to base-4.7.0.0-d4a0afe8e5c5f0dff2237b1231b56978
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.9.0.0-f798cb95c80f3e3751ec33b413381b57
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags:
wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-ce20d91f79b43ede95508e8cfd2188b0
wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-67cd00feecdc491a633c46b0f7652b46
wired-in package base mapped to base-4.7.0.0-d4a0afe8e5c5f0dff2237b1231b56978
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.9.0.0-f798cb95c80f3e3751ec33b413381b57
wired-in package dph-seq not found.
wired-in package dph-par not found.
*** Chasing dependencies:
Chasing modules from: *asd.hs
Stable obj: []
Stable BCO: []
Ready for upsweep
[NONREC
ModSummary {
ms_hs_date = 2014-03-10 04:11:51 UTC
ms_mod = main:Main,
ms_textual_imps = [import (implicit) Prelude]
ms_srcimps = []
}]
*** Deleting temp files:
Deleting:
compile: input file asd.hs
Created temporary directory: C:\Users\facuq\AppData\Local\Temp\ghc6824_1
*** Checking old interface for main:Main:
[1 of 1] Compiling Main ( asd.hs, asd.o )
*** Parser:
*** Renamer/typechecker:
*** Desugar:
Result size of Desugar (after optimization)
= {terms: 7, types: 5, coercions: 0}
*** Simplifier:
Result size of Simplifier = {terms: 7, types: 5, coercions: 0}
*** Tidy Core:
Result size of Tidy Core = {terms: 7, types: 5, coercions: 0}
*** CorePrep:
Result size of CorePrep = {terms: 9, types: 6, coercions: 0}
*** Stg2Stg:
*** CodeOutput:
*** New CodeGen:
*** CPSZ:
*** CPSZ:
It's actually a bug in GHC; it was confirmed on the GHC mailing list, and two people can reproduce it (ghc's bug manager thread).
your ghc.exe path and cabal.exe path should be in your path variable
It has worked for me.

installing cairo on Mac OS Lion

I've just got a new mac, and I'm struggling to install Cairo for use with Haskell (diagrams in particular). I remember having a lot of problems with my previous machine, but I'm at a dead end this time.
$ cabal install cairo
Resolving dependencies...
[1 of 2] Compiling SetupWrapper ( /var/folders/7s/6fn_d5px0hs2204xfztw88v40000gp/T/cairo-0.12.3.1-66116/cairo-0.12.3.1/SetupWrapper.hs, /var/folders/7s/6fn_d5px0hs2204xfztw88v40000gp/T/cairo-0.12.3.1-66116/cairo-0.12.3.1/dist/setup/SetupWrapper.o )
[2 of 2] Compiling Main ( /var/folders/7s/6fn_d5px0hs2204xfztw88v40000gp/T/cairo-0.12.3.1-66116/cairo-0.12.3.1/Setup.hs, /var/folders/7s/6fn_d5px0hs2204xfztw88v40000gp/T/cairo-0.12.3.1-66116/cairo-0.12.3.1/dist/setup/Main.o )
Linking /var/folders/7s/6fn_d5px0hs2204xfztw88v40000gp/T/cairo-0.12.3.1-66116/cairo-0.12.3.1/dist/setup/setup ...
[1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o )
[2 of 2] Compiling Main ( SetupMain.hs, dist/setup-wrapper/Main.o )
Linking dist/setup-wrapper/setup ...
Configuring cairo-0.12.3.1...
setup: The program pkg-config version >=0.9.0 is required but it could not be
found.
cabal: Error: some packages failed to install:
cairo-0.12.3.1 failed during the configure step. The exception was:
ExitFailure 1
The program pkg-config needs to be installed. There are various ways to do this (e.g. I imagine it's available as part of MacPorts and similar package managers) but in the event that you need to download and install it from source, this is the place:
http://www.freedesktop.org/wiki/Software/pkg-config/

Can't install gtk-mac-integration

I don't understand the error because it appears to be requiring a version of the same package that I'm trying to install.
$ cabal install gtk-mac-integration
Resolving dependencies...
[1 of 2] Compiling SetupWrapper ( /var/folders/cU/cUDMo9+9Gl817+j+h1DAvk+++TI/-Tmp-/gtk-mac-integration-0.1.0.46479/gtk-mac-integration-0.1.0.4/SetupWrapper.hs, /var/folders/cU/cUDMo9+9Gl817+j+h1DAvk+++TI/-Tmp-/gtk-mac-integration-0.1.0.46479/gtk-mac-integration-0.1.0.4/dist/setup/SetupWrapper.o )
[2 of 2] Compiling Main ( /var/folders/cU/cUDMo9+9Gl817+j+h1DAvk+++TI/-Tmp-/gtk-mac-integration-0.1.0.46479/gtk-mac-integration-0.1.0.4/Setup.hs, /var/folders/cU/cUDMo9+9Gl817+j+h1DAvk+++TI/-Tmp-/gtk-mac-integration-0.1.0.46479/gtk-mac-integration-0.1.0.4/dist/setup/Main.o )
Linking /var/folders/cU/cUDMo9+9Gl817+j+h1DAvk+++TI/-Tmp-/gtk-mac-integration-0.1.0.46479/gtk-mac-integration-0.1.0.4/dist/setup/setup ...
[1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o )
[2 of 2] Compiling Main ( SetupMain.hs, dist/setup-wrapper/Main.o )
Linking dist/setup-wrapper/setup ...
Configuring gtk-mac-integration-0.1.0.4...
setup: The pkg-config package gtk-mac-integration version >=0.9.6 is required
but it could not be found.
cabal: Error: some packages failed to install:
gtk-mac-integration-0.1.0.4 failed during the configure step. The exception
was:
ExitFailure 1
It doesn't want the Haskell package gtk-mac-integration, it wants the system package gtk-mac-integration. That is, the Haskell package you're trying to install is just a binding to the gtk-mac-integration library (which I think is bundled with GTK+); you'll have to install it separately before you can install the Haskell package.
If you already have GTK+ installed, then the problem is that the pkg-config tool Cabal uses to find external library dependencies can't find the corresponding .pc files for the library. I don't know how to fix that, though; at least not without more details.

Resources