Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [ghc]

Glasgow Haskell Compiler is a state-of-the-art, open source compiler and interactive environment for the functional language Haskell. Use this tag for questions specifically about GHC and not about Haskell in general as almost everyone will be using it unless specified otherwise.

1
vote
0answers
27 views

stack install ghc-mod fails to construct build plan

I've been trying to install ghc-mod locally within a Stack project. However, whenever I try to stack build ghc-mod, I get a build plan failure like the following: Error: While constructing the ...
3
votes
1answer
196 views

GHC: how to build a 32-bit DLL using 64-bit GHC? (To call functions from c++)

I'd like to build the 32-bit DLL with 64-bit GHC. And here is the minimal example. Test.hs {-# LANGUAGE ForeignFunctionInterface #-} module Test where import Foreign.C.Types foreign export ccall ...
0
votes
3answers
59 views

I am getting different results when running my Haskell code interactively using ghci and when loading it as a module

Code loaded from .hs file: modPow :: Int -> Int -> Int -> Int modPow a k m = (a^2 `mod` m)^(k `div` 2) code entered interactively: (13481503^2 `mod` 46340)^(11237126 `div` 2) i.e a = ...
35
votes
4answers
6k views

Understanding STG

The design of GHC is based on something called STG, which stands for "spineless, tagless G-machine". Now G-machine is apparently short for "graph reduction machine", which has how laziness is ...
3
votes
1answer
66 views

Passing -ddump-splices to Stack script interpreter

I'm using Stack interpreter feature and having a code like this: #!/usr/bin/env stack {- stack --resolver lts-9.0 --install-ghc runghc --package yesod --package yesod-core -} ...
1
vote
0answers
51 views

Stack always downloads ghc eventhough it is in path

enter image description here Hello, I am from India. The reason why I have mentioned this would be evident shortly. I want to use Haskell into my computer currently running Windows 10 build 1803, and ...
2
votes
0answers
56 views

How to determine the types of all subexpressions in a Haskell program?

I am working on a Haskell project that requires me to convert a Haskell program to its GHC Core form and annotate each sub-expression with its type. For example, given the factorial function: fac 0 =...
4
votes
0answers
67 views

Haskell DLL causes memory leak

I am working on a C++ project that uses a Haskell DLL (GHC version is 8.0.1 x64). I've noticed, that the executing program consumes much memory. I investigated into the matter and that's what I've ...
0
votes
0answers
14 views

ghc 7.10 install onto linux mint

I've got a problem to compile HarmTrace . I really need to work with this program. On the Installation instructions appears that: "However, Stack helps considerably. One of the difficulties is that ...
0
votes
1answer
50 views

Haskell cannot match expected type 'Bool' to type [t0]

New to haskell and I keep running into this cryptic error when I try to pattern match a non empty list Code: type Bits = [Bool] nor :: Bits -> Bits -> Bits nor [] [_:__] = error "mismatched ...
3
votes
1answer
161 views

Is there a way to disable the constant folding optimization in GHC?

I need to compiler some Haskell source code with GHC -O1 optimization but with the constant folding optimization disabled. I could not find an optimization flag for toggling constant folding in GHC ...
2
votes
1answer
89 views

Does GHC support GC-less programming?

With -S option and a simple program: main = do print "Hello" main I can see that it produces some garbage: [...] 1024232 4904 45992 0.000 0.000 0.428 0.530 0 0 (Gen: ...
3
votes
0answers
67 views

In GHC-8.2.2, can overlapping instance resolution depend on whether a file is included as an exposed module?

I'm encountering the following hard to understand behavior from GHC-8.2.2 I have some overlapping typeclass instances. No incoherent typeclass instances. There's a certain typeclass instance of the ...
1
vote
0answers
62 views

Inner loop constructors not eliminated by GHC

I am trying to, roughly, play with different stream fusion approaches to the code sum (filter even [0..n]) and have reached a point where I would expect constructor specialization to kick in (with -...
2
votes
0answers
62 views

Making a type constraint based on runtime value of (maxBound :: Int)

I'm very new to type-level computations and type families and so on, and I'm trying to make a Constraint that will keep a type-level Nat from exceeding maxBound :: Int. In order to future-proof the ...
27
votes
2answers
20k views

How to execute a command right after a fetch or pull command in git?

I cloned the GHC (Glasgow Haskell Compiler) repository. In order to build the compiler, you need several libraries, all of them are available as git repositories too. In order to ease ones live, the ...
2
votes
1answer
81 views

GHC make explicit forall mandatory

The language extension ExplicitForall makes it possible but not required to bind type variables with forall. For example, the following program compiles {-# LANGUAGE ExplicitForAll #-} -- cps1.hs -...
3
votes
1answer
42 views

How to align in memory the array payload of a ByteArray# with GHC Haskell

I have a few questions about how to align not a ByteArray# but a ByteArray#'s array payload (the actual bytes of nonmetadata data stored in the array), which might be complicated by the fact that the ...
6
votes
0answers
174 views

Calling Haskell from Common Lisp (SBCL)

I am trying to call Haskell (ghc version 7.6.3) from Common Lisp (sbcl version 1.2.4) on a debian pc. The Haskell code is {-# LANGUAGE ForeignFunctionInterface #-} module Safe where import ...
20
votes
1answer
117 views

Significance of scoped type variables standing for type variables and not types

In the GHC documentation for the ScopedTypeVariables extension, the overview states the following as a design principle: A scoped type variable stands for a type variable, and not for a type. (...
0
votes
0answers
39 views

Ho can I solve cabal error installing ghc-syb-utils?

I am a newbie in the Haskell ecosystem. I am trying to install hsdev on my mac and during the installation, cabal fails to build ghc-syb-utils. So I tried to install it instead, and I have this error: ...
8
votes
1answer
72 views

Setting import path in an OPTIONS pragma

According to the GHC 8.4.3 flag reference, the -i flag is dynamic, which means it should be settable by an OPTIONS pragma. So I tried the following: . ├── Main.hs └── imp └── Imported.hs ...
16
votes
5answers
5k views

Using cabal with multiple GHC versions

I got both ghc6 and ghc7 on my desktop. To install new packages (for the specific ghc version), I use cabal with the flag --with-compiler=<ghc-dir> to specify for which ghc i want the package ...
3
votes
0answers
86 views

Stack - gcc ISO C99 compiler support missing

After moving the contents of my old computer to a new one, I tried to continue working on a haskell project with Stack, but stack build commands no longer work. The initial issue was with the user ...
17
votes
1answer
189 views

Code unexpectedly accepted by GHC/GHCi

I don't understand why this code should pass type-checking: foo :: (Maybe a, Maybe b) foo = let x = Nothing in (x,x) Since each component is bound to the same variable x, I would expect that the ...
2
votes
2answers
57 views

Why does expanding my functional dependency eliminate non-type variable arguments?

I've been doing some work building my own custom prelude and I wanted to build a Callable type class that would implement function application (($)) for types other than functions. So I built a type ...
3
votes
2answers
172 views

How to disable the <<loop>> exception when compiling Haskell with GHC?

If my program reaches an infinite loop, I would like it to actually get stuck: run forever, run out of memory or crash with a stack overflow. I don't want it to quit immediately with the <<loop&...
15
votes
1answer
196 views

Haskell explicit recursion vs `iterate`

While writing a function using iterate in Haskell, I found that an equivalent version with explicit recursion seemed noticeably faster - even though I believed that explicit recursion ought to be ...
8
votes
1answer
500 views

What's the right way to :reload and run :main as a single command in GHCi?

Is there a way to chain :reload/:r along with :main as a single command in GHCi? The goal here is to avoid typing both every time I change something in my other terminal, but to just type ↑Enter....
0
votes
2answers
110 views

Haskell: Can a function be compiled?

Consider a simple Haskell Brainf*ck interpreter. Just look at the interpret function. import Prelude hiding (Either(..)) import Control.Monad import Data.Char (ord, chr) -- function in question ...
1
vote
1answer
61 views

Why isn't GHCi letting me annotate my types with kinds?

I found out about Kinds while reading a History of Haskell paper and tried to run some of the examples at the Haskell Wiki. When I do, I get the error Prelude> Int :: * ...
1
vote
1answer
53 views

Enrich constraint solver with own proofs

I have the following type family: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} data Nat = Z | S Nat type family WrapMaybes (n :: Nat) (a :: *) :: * type instance WrapMaybes Z a = a type ...
18
votes
1answer
151 views

Is it possible to invert the order errors are displayed?

When compiling a faulty program with GHC, errors are displayed in ascending line order. That causes the first errors to get pushed up the console, so you need to scroll up if you work by fixing the ...
0
votes
1answer
16 views

Why is the GHC version not as expected when building with stack nightly?

What goes into determining the GHC version when using stack? I thought this would be the resolver but... I have the following stack file: resolver: nightly-2018-07-10 packages: - . This is what is ...
1
vote
1answer
62 views

How to specify path to `llvm` for `ghc` and `cabal`?

I'm trying to add the new llvm path to cabal to build with -fllvm option because I receive the error that it can't see the newer version: <no location info>: error: Warning: Couldn't figure ...
5
votes
2answers
100 views

Why is this not a case of the restricted monad limitation?

In the following code snippet I initially believed to have a restricted monad error (I forgot to add the Monad m => in the instance Monad (Transform m a) definition). Having read quite a bit about ...
0
votes
1answer
67 views

Windows 10 ghc 8.4.3 Add Library Search Path Error

I have run into a strange ghci addLibrarySearchPath error message with Haskell Platform 8.4.2 and 8.4.3 full on a Windows 10 Pro version 1803 machine. Here is an example transcript on a fresh ...
1
vote
1answer
31 views

Profiling/coverage: counting case alternative evaluations

hpc markup --fun-entry-count shows the number of times a top-level function has been entered. I'm wondering if there is a similar option for other syntactic entities, in particular case alternatives. ...
0
votes
0answers
73 views

Are space-leaks in GHC Haskell always fixable?

As I learn about Haskell, I'm getting impression that surprising space leaks (also here) are one of the most important barriers to adoption. It's not clear to me whether any program can always be ...
34
votes
5answers
5k views

How to stop GHC from generating intermediate files?

When compiling a haskell source file via ghc --make foo.hs GHC always leaves behind a variety of intermediate files other than foo.exe. These are foo.hi and foo.o. I often end up having to delete the ...
1
vote
0answers
41 views

Reenable hidden package suggestions from GHC

Previously, GHC would inform me when I tried to import a module from an installed, but hidden, package: Could not find module 'Foo' It is a member of the hidden package 'foo-0.1.0.0'. Perhaps you ...
30
votes
1answer
3k views

Understanding GHC assembly output

When compiling a haskell source file using the -S option in GHC the assembly code generated is not clear. There's no clear distinction between which parts of the assembly code belong to which parts of ...
19
votes
2answers
343 views

How to properly link object files written in Haskell?

Roughly following this tutorial, I managed to get this toy project working. It calls a Haskell function from a C++ program. Foo.hs {-# LANGUAGE ForeignFunctionInterface #-} module Foo where ...
6
votes
0answers
63 views

Using GHC API to compile a program with optimisation

I want to compile a Haskell module to GHC Core, with optimisations applied, and use the resulting core output. However, when I use compileToCoreSimplified it doesn't seem to run all the normal ...
61
votes
4answers
26k views

How to run a haskell file in interpreted mode

I've been told you can interpret haskell files (which I assume means they will work like Ruby/Python/Perl). Can't find the command line option on ghc to do this, though. It always wants to compile my ...
2
votes
1answer
61 views

How does GHC infer the intended type for this GADT?

My understanding of GHC type inference was that in the absence of type annotations, it will default to Hindley-Milner. However, to my pleasant surprise GHC infers Num p => G a -> p for f as ...
7
votes
1answer
295 views

pthread_cond_timedwait does not return in GHC FFI

I've tried to implement Haskell Control.Concurrent.MVar that resides in shared memory and allows communicating between multiple independent processes/programs using POSIX functionality. But I have ...
19
votes
1answer
138 views

How do I determine why ghc is looking for a particular type class instance?

When conditional type class instances run deep, it can be difficult to figure out why ghc is complaining about a missing type class instance. For instance: class MyClass1 c class MyClass2 c class ...
1
vote
0answers
69 views

Haskell Stack Generating Duplicate Dependency?

So I am in the process of updating my Haskell project from LTS 9.21 (GHC 8.0.2) to LTS 11.12 (GHC 8.2.2) and one of my existing projects no longer compiles properly (OS: archlinux). Specifically the ...
11
votes
2answers
326 views

How can I track down GHC “Couldn't match expected type” errors?

This Haskell code contains a type error, a dumb mistake on my part that will be obvious once you see it. I figured it out, but it was hard. My question is: How should I have gone about diagnosing ...