FAQ Database Discussion Community


Will GHC strip out unused imports?

haskell,ghc
When I don’t use certain imports from the main function (which should be easily detectable), will GHC strip out the corresponding bindings? Example: import Text.Parsec (parse) import My.Testframework (test) main = parse … tests = test … Will My.Testframework be linked in the executable?...

Haskell make recipe fails for Paradox theorem prover using GHC

linux,haskell,make,ghc,theorem-proving
I am trying to install the paradox theorem prover sourced from here. When I run the makefile this is the command that runs: ghc -optl -static -lstdc++ -I../instantiate -I../minisat/current-base ../minisat/current-base/Solver.or ../minisat/current-base/Prop.or ../instantiate/MiniSatWrapper.or ../instantiate/MiniSatInstantiateClause.or -fglasgow-exts -O2 -static -threaded -main-is Paradox.Main.main --make Paradox.Main -o paradox And it results in several errors like...

Matching positive integer with haskell

haskell,pattern-matching,ghc
Is it possible with pattern matching to match a range of values ? For example : the whole positive integers ? odd numbers ? a list of values ? ...

IntelliJ publigin: ghc-modi error output: NG quit

haskell,intellij-idea,ghc,ghc-mod
I'm just using GHC 7.8.4 and cabal 1.22.0.0 with IntelliJ Haskell plugin. After starting my project, I receive this error log ghc-modi failed ghc-modi failed with error: NG BUG: cabal: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory) You can disable ghc-modi in Settings | Haskell IOException:...

How to keep very big elements on memory without exhausting the garbage collector?

haskell,optimization,garbage-collection,ghc
In Haskell, I created a Vector of 1000000 IntMaps. I then used Gloss to render a picture in a way that accesses random intmaps from that vector - that is, I had keep every single one of them in memory. The rendering function itself is very lightweight, so the performance...

Linking with GHC

c,haskell,makefile,ghc,webots
I am following this short tutorial and trying to compile Webots application (written in C) using GHC (Glasgow Haskell Compiler, Version 7.10.1) with following command: ghc --make -no-hs-main -optc-O -I"/Applications/Webots/include/controller/c/" -L"/Applications/Webots/lib/" -outputdir build/release/ advanced_genetic_algorithm_supervisor.c Safe -o advanced_genetic_algorithm_supervisor and getting the following error during the linking phase: Linking advanced_genetic_algorithm_supervisor ... Undefined...

GHC can not find installed module

haskell,package,ghc
My haskell installation can not find bytestring module installed by operating system $ ghci GHCi, version 7.6.3: 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 +Data.ByteString.Lazy <no location info>: Could not...

Couldn't match expected type `()' with actual type `Int'

haskell,ghc,gtk2hs
I have a strange error with Haskell and Gtk2Hs. I try to set the cursor position in a text entry with set entree [entryCursorPosition := 5 ] which correspond to the Type entryCursorPosition :: EntryClass self => ReadAttr self Int and I have the following error : Couldn't match expected...

Real World Haskell, Chapter 5, SimpleJSON compile error

haskell,ghc,real-world-haskell
According to another question, parts of Real World Haskell are now obsolete. I'm only on Chapter 5, but I'm having problems compiling a simple example to an executable binary. Two modules are given: module SimpleJSON ( JValue(..) , getString , getInt , getDouble , getBool , getObject , getArray ,...

How do I add Data.Bits to Data.Modular, automatically?

haskell,polymorphism,ghc
I need to xor a couple of mod numbers (from Data.Modular).... let x = 4 :: Integer `Mod` 10 y = 6 :: Integer `Mod` 10 print $ x `xor` y ....but, this doesn't work, because Mod x y is not an instance of Data.Bits. I can, or course, convert...

Haskell: odd difference between compiled vs interpreted functions which print concatenated infinite lists

list,haskell,ghc,ghci
I'm just exploring Haskell for fun, and to learn about the language. I thought the following behavior was interesting, and I can't find the reason why this happens. This is an often quoted piece of Haskell code which keeps calculating pi until interrupted, slightly modified to give a concatenated list...

GHC complains about overlapping instances when in fact they are not

haskell,ghc,instances
I have the function toAVector defined like this: class Elt a => ToAVector v a where toAVector :: v a -> A.Array DIM1 a instance Elt a => ToAVector [] a where toAVector l = A.fromList (Z :. P.length l) l instance (Elt a, G.Vector v a) => ToAVector v...

How to compile *.hs to llvm ir (*.ll) using GHC compiler?

haskell,llvm,ghc
I tried ghc -fllvm -pgmlo -pgmlc -ddump-llvm src.hs and ghc -fllvm -pgmlo -pgmlc -keep-llvm-files src.hs opt and llc (3.5.1 version) are in PATH But I haven't found any llvm ir after I executed commands....

Could not deduce (a ~ Double) with Haskell

haskell,types,ghc,typeclass
I have a typing problem with a Haskell function. I implemented this (simplified) function : function (xa,ya,za) (xb,yb,zb) (Size tai) = function (xa,ya,za) (xb,yb,zb) (Ndiv ndiv) where ndiv = ceiling (leng / tai) leng = sqrt((xb-xa)**2+(yb-ya)**2+(zb-za)**2) data Method = Ndiv Int | Size Double It working well if I give...

Get number of threads (HECs) at runtime

haskell,ghc
How do I get the number of threads / HECs (the -N parameter) of a Haskell program that was compiled with -threaded during its runtime? [Edit] My question is about the number of HECs, not about the number of cores (even though the answer is related) - so the question...

Why doesn't sleep work?

haskell,ghc,ffi
Why does c_sleep return immediately in the following code? {-# LANGUAGE ForeignFunctionInterface #-} import Foreign.C.Types import Data.Time.Clock import Control.Concurrent foreign import ccall unsafe "unistd.h sleep" c_sleep :: CUInt -> IO CUInt main :: IO () main = do getCurrentTime >>= print . utctDayTime c_sleep 10 >>= print -- this doesn't...

Do GHC REWRITE pragmas have to be type preserving?

haskell,ghc,pragma
import Data.Void (Void,absurd) Say I have a small term language: data Term c v where Var :: v -> Term c v Con :: c -> [Term c v] -> Term c v If I want to combine terms of the type Term c Void and Term c Int, that...

How to put constraints on type variable of kind `Constraint`?

haskell,ghc,typeclass,gadt
I'm playing around with the ConstraintKinds extension of GHC. I have the following data type, which is just a box for things fulfilling some one parameter constraint c: data Some (c :: * -> Constraint) where Some :: forall a. c a => a -> Some c For example, I...

GHCI 7.8.3 does not support utf8 characters

haskell,utf-8,ghc,ghci
I've read in the utf8-string package that ghc should support utf8 by default. I've even seen somewhere being written that now my default codepage is used. Despite all that, a simple code does not execute. writeFile "asd.txt" "ćlččć" returns *** Exception: filenames.txt: commitBuffer: invalid argument (invalid character) How do I...

Force GHC using local files

haskell,build,ghc,cabal
I'm making some "experiments" on a haskell module and I have a problem with a source file I wish to modify. I have many reasons to think that GHC seek the installed (with cabal) library on my system and not the local sources files. I deleted the *.o files locally...

GHC version check in code

haskell,ghc
I'm contributing to Alex, and it obviously depends on a lot of libraries and should compile for a lot of versions. I need to use a function that is only available from GHC 7.6.1 to handle an error better. So I want to use an #if ... to import said...

ghc-7.10: Non type-variable argument (Use FlexibleContexts to permit this)

haskell,ghc,parsec
I was trying to use ghc-7.10 (RC 2) and got this message in a number of cases, e.g., src/Text/Regex/XMLSchema/Generic/RegexParser.hs:439:5: Non type-variable argument in the constraint: Text.Parsec.Prim.Stream s m Char (Use FlexibleContexts to permit this) When checking that ‘prop’ has the inferred type prop :: forall s u (m :: *...

Progress messages not appearing with cabal install for some users

haskell,configuration,ghc,cabal,cabal-install
I'm working on a team project using Haskell and whenever I compile our project using 'cabal install' I start seeing the following: $ cabal clean && cabal install cleaning... Resolving dependencies... Configuring hackathon-0.1... Building hackathon-0.1... Preprocessing executable 'hackathon' for hackathon-0.1... [ 1 of 65] Compiling Data.MaybeUtil ( src/Data/MaybeUtil.hs, dist/dist-sandbox-52369b17/build/hackathon/hackathon-tmp/Data/MaybeUtil.o )...

Can a Haskell/GHC self-report its GC stats live?

haskell,ghc
I'm thinking that having a server to self-report its memory usage would be handy. I have read the section on memory profiling in the manual, but there are a few drawbacks with this: First this seems to give only post-mortem stats. There is an overhead associated with enabling profiling. I...

Weakening vinyl's RecAll constraint through entailment

haskell,constraints,ghc,vinyl
In the vinyl library, there is a RecAll type family, which let's us ask that a partially applied constraint is true for every type in a type level list. For example, we can write this: myShowFunc :: RecAll f rs Show => Rec f rs -> String And that's all...

Bundling constraints with fundeps

haskell,ghc,functional-dependencies,type-constraints
I've got a function foo with a litany of constraints. Of course these constraints must appear in the signatures of functions that use foo, so what I'm trying to do is wrap the foo constraints in a type synonym FooCtx a b ... :: Constraint. As an example, foo ::...

Parsing string into data type : better error messages?

parsing,haskell,ghc
Currently I am parsing strings into data types using the read function from Text.Read as shown in the example below : module Main where data Inner = Inner { x :: Int , y :: Double } deriving (Read,Show) data Outer = Outer { inner :: Inner } deriving (Read,Show)...

Haskell strange type inference narrowing [duplicate]

haskell,ghc,type-inference,ghci
This question already has an answer here: Type inference of a function in GHCi differs with loaded from a file 1 answer GHCi 7.8.3 filter (\(a,b) -> a>0) :: (Ord a, Num a) => [(a, t)] -> [(a, t)] as expected ^ fstGt0 xs = filter (\(a,b) -> a>0)...

Wrong argument kind when using GHC Generics

haskell,types,ghc,typeclass
I've been following the GHC.Generics tutorial to make a simple generic typeclass for providing default values for arbitrary types. However when I try to load my file (relevant snippet, which still produces the error) {-# LANGUAGE DefaultSignatures, DeriveGeneric, TypeOperators, FlexibleContexts #-} import GHC.Generics class Default a where def :: a...

Bytestring - package version number mismatch

haskell,ghc
I am trying to run hafka on my system. And for same element type, Data.ByteString.Internal.ByteString, haskell throws error due to version number mismatch. Couldn't match expected type ‘bytestring-0.10.4.0:Data.ByteString.Internal.ByteString’ with actual type ‘B.ByteString’ NB: ‘bytestring-0.10.4.0:Data.ByteString.Internal.ByteString’ is defined in ‘Data.ByteString.Internal’ in package ‘bytestring-0.10.4.0’ ‘B.ByteString’ is defined in ‘Data.ByteString.Internal’ in package ‘bytestring-0.10.6.0’ On...

Distribute a closed source haskell module [closed]

haskell,ghc,cabal,proprietary
Is it possible to distribute a Haskell binary module with Cabal without giving the source code ? If it is possible : What would be the files to include in the package ? What would be the precautions to take about the compiler options, compatible versions, ... ? Will the...

How to implement recursive function?

haskell,ghc
Below defines an Algebraic Data Type IntList : data IntList = Empty | Cons Int IntList The function intListProd computes the product of IntList type : intListProd :: IntList -> Int intListProd Empty = 1 intListProd (Cons x l) = x * intListProd l But I'm unsure how to create...

Getting the GHC to accept type signature with KnownNat arithmetic

haskell,math,ghc,number-theory
I have been trying to implement the Chinese Remainder Theorem, for the specific case of just two equations, using the Data.Modular package. The idea is that I can specify each equation with only one modular number (x = a (mod m) using the number a (mod m)). Here is my...

Should GHC be linking different versions of the same libraries?

haskell,linker,ghc
I'm trying to compile a program with GHC 7.6.3 and I get the error /usr/lib/ghc/unix-2.6.0.1/libHSunix-2.6.0.1.a(execvpe.o): In function `pPrPr_disableITimers': (.text+0x300): multiple definition of `pPrPr_disableITimers' /home/tom/.cabal/lib/i386-linux-ghc-7.6.3/unix-2.7.1.0/libHSunix-2.7.1.0.a(ghcrts.o):ghcrts.c:(.text+0x0): first defined here collect2: error: ld returned 1 exit status (The problem ultimately derives from a usage of readProcessWithExitCode but I don't think that's especially relevant)...

Haskell inbuilt libraries, where does it go?

haskell,ghc,bytestring
In my /home/sk/.ghc/x86_64-linux-7.8.4/package.conf.d folder, there is an entry for bytestring package as, bytestring-0.10.6.0-7682cf7d45ee92d104399a67f3bce6ba.conf In my /opt/ghc/7.8.4/lib/ghc-7.8.4/package.conf.d folder, there is an entry for bytestring as, bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5.conf Why does haskell store bytestring libraries in two different places. This is leading to compilation errors due to type/version mis-match. How can i ensure, only...

Excessive mysterious system time use in a GHC-compiled binary

linux,performance,haskell,virtual-machine,ghc
I'm working on an exploration of automatic bounding of constraint-base searches. As such, my starting point is the SEND MORE MONEY problem, with a solution based on nondeterministic selection without replacement. I've modified the approach to count the number of samples performed, in order to better measure the impact of...

How to bring a data kind to the value level?

haskell,ghc
I have something like this in my code: data SomeKind = Kind1 | Kind2 deriving Eq data SomeValue (t :: SomeKind) = SomeValue someValue1 :: SomeValue Kind1 someValue1 = SomeValue someValue2 :: SomeValue Kind2 someValue2 = SomeValue I want to get the kind that's in the type level to the...

Gtk2Hs : Existing function not found

haskell,ghc,gtk2hs
I have a problem with Gtk2Hs, I want to set a cellRenderer activatable. For that, I need to set it's property cellMode to CellRendererModeActivatable by using : set render [ cellMode:= CellRendererModeActivatable ] But I have the following error when compiling Not in scope: data constructor `CellRendererModeActivatable' I'm using Gtk2Hs...

Why aren't the earlier terms here being garbage-collected?

haskell,memory,garbage-collection,ghc,compiler-optimization
If I define the Kolakoski Sequence as kolakoski :: () -> [Int] kolakoski () = 1 : 2 : helper () where helper () = 2 : concat (zipWith replicate (helper ()) (cycle [1, 2])) and find the 500,000,000th term with kolakoski () !! 500000000 I find that when compiled...

What is wrong with my Haskell definition of the bind operator in this example?

haskell,monads,ghc,ghci
I'm following a monad transformers tutorial here. At this point in the tutorial, it asks me to try to implement the Monad instance for the EitherIO data type, defined as: data EitherIO e a = EitherIO { runEitherIO :: IO (Either e a) } So I tried: instance Functor (EitherIO...

Understanding `GHC.TypeLits`

haskell,ghc
I'm trying to wrap my head around the GHC extensions KindSignatures and DataKinds. Looking at the Data.Modular package, I understand roughly that newtype i `Mod` (n :: Nat) = Mod i deriving (Eq, Ord) is sort of equivalent to declaring a c++ template <typename T, int N> (with the constructor...