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.

The Glasgow Haskell Compiler (GHC) is the most commonly used compiler for . Apart from supporting the language standards (Haskell 98 and Haskell 2010), it also supports a wide variety of language extensions like generalized algebraic data types (GADTs) and multi-parameter type classes.

As GHC is by far the most used Haskell compiler, it is safe to assume that anyone is using it unless specified otherwise. This means the GHC tag should be used for questions relating directly to the compiler or to its APIs, and not for questions about Haskell in general.

GHC also exports most of its functionality as a Haskell API - the compiler itself can also act like a library. This tag should also be used for any questions pertaining to the GHC API.

Other resources:

2470 questions
393
votes
1 answer

Transitivity of Auto-Specialization in GHC

From the docs for GHC 7.6: [Y]ou often don't even need the SPECIALIZE pragma in the first place. When compiling a module M, GHC's optimiser (with -O) automatically considers each top-level overloaded function declared in M, and specialises it for…
crockeea
  • 21,651
  • 10
  • 48
  • 101
377
votes
8 answers

What does the `forall` keyword in Haskell/GHC do?

I'm beginning to understand how the forall keyword is used in so-called "existential types" like this: data ShowBox = forall s. Show s => SB s This is only a subset, however, of how forall is used and I simply cannot wrap my mind around its use in…
JUST MY correct OPINION
  • 35,674
  • 17
  • 77
  • 99
335
votes
3 answers

Why is Haskell (GHC) so darn fast?

Haskell (with the GHC compiler) is a lot faster than you'd expect. Used correctly, it can get close-ish to low-level languages. (A favorite thing for Haskellers to do is to try and get within 5% of C (or even beat it, but that means you are using an…
PyRulez
  • 10,513
  • 10
  • 42
  • 87
323
votes
2 answers

Techniques for Tracing Constraints

Here's the scenario: I've written some code with a type signature and GHC complains could not deduce x ~ y for some x and y. You can usually throw GHC a bone and simply add the isomorphism to the function constraints, but this is a bad idea for…
crockeea
  • 21,651
  • 10
  • 48
  • 101
212
votes
2 answers

When is -XAllowAmbiguousTypes appropriate?

I've recently posted a question about syntactic-2.0 regarding the definition of share. I've had this working in GHC 7.6: {-# LANGUAGE GADTs, TypeOperators, FlexibleContexts #-} import Data.Syntactic import Data.Syntactic.Sugar.BindingT data Let a…
crockeea
  • 21,651
  • 10
  • 48
  • 101
204
votes
4 answers

Reading GHC Core

Core is GHC's intermediate language. Reading Core can help you better understand the performance of your program. Someone asked me for documentation or tutorials on reading Core, but I couldn't find much. What documentation is available for reading…
tibbe
  • 8,809
  • 7
  • 36
  • 64
196
votes
3 answers

What optimizations can GHC be expected to perform reliably?

GHC has a lot of optimizations that it can perform, but I don't know what they all are, nor how likely they are to be performed and under what circumstances. My question is: what transformations can I expect it to apply every time, or nearly so? If…
glaebhoerl
  • 7,695
  • 3
  • 30
  • 41
156
votes
1 answer

Specialization with Constraints

I'm having problems getting GHC to specialize a function with a class constraint. I have a minimal example of my problem here: Foo.hs and Main.hs. The two files compile (GHC 7.6.2, ghc -O3 Main) and run. NOTE: Foo.hs is really stripped down. If you…
crockeea
  • 21,651
  • 10
  • 48
  • 101
153
votes
6 answers

Why is GHC so large/big?

Is there a simple answer: Why is GHC so big? OCaml: 2MB Python: 15MB SBCL: 9MB OpenJRE - 26MB GHC: 113MB Not interested in evangelism of "Why I shouldn't care about the size if Haskell is the right tool"; this is a technical question.
Christopher Done
  • 5,886
  • 4
  • 35
  • 38
141
votes
2 answers

Does GHC-mod have to use full names for types?

I'm trying to use the ghc-mod vim plugin to do type/syntax checking etc. However, I found that ghc-mod always uses full paths of types in the error messages, for example: test.hs|71 col 13 error| Couldn't match type ‘Data.Text.Internal.Text’ …
xzhu
  • 5,675
  • 4
  • 32
  • 52
139
votes
5 answers

Reducing garbage-collection pause time in a Haskell program

We are developing a program which receives and forwards "messages", while keeping a temporary history of those messages, so that it can tell you the message history if requested. Messages are identified numerically, are typically around 1 kilobyte…
jameshfisher
  • 34,029
  • 31
  • 121
  • 167
137
votes
2 answers

Small Haskell program compiled with GHC into huge binary

Even trivially small Haskell programs turn into gigantic executables. I've written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB! What can cause even a small Haskell program to be compiled to the huge…
user181351
128
votes
2 answers

Memory footprint of Haskell data types

How can I find the actual amount of memory required to store a value of some data type in Haskell (mostly with GHC)? Is it possible to evaluate it at runtime (e.g. in GHCi) or is it possible to estimate memory requirements of a compound data type…
sastanin
  • 40,473
  • 13
  • 103
  • 130
113
votes
1 answer

Why does Haskell's "do nothing" function, id, consume tons of memory?

Haskell has an identity function which returns the input unchanged. The definition is simple: id :: a -> a id x = x So for fun, this should output 8: f = id id id id id id id id id id id id id id id id id id id id id id id id id id id main = print…
Ryan
  • 2,378
  • 1
  • 19
  • 29
112
votes
4 answers

When is memoization automatic in GHC Haskell?

I can't figure out why m1 is apparently memoized while m2 is not in the following: m1 = ((filter odd [1..]) !!) m2 n = ((filter odd [1..]) !! n) m1 10000000 takes about 1.5 seconds on the first call, and a fraction of that on subsequent…
Jordan
  • 1,121
  • 2
  • 8
  • 3
1
2 3
99 100