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
37
votes
1 answer

How does IncoherentInstances work?

Playing around with some code: {-# LANGUAGE FlexibleInstances, OverlappingInstances #-} class Arity f where arity :: f -> Int instance Arity x where arity _ = 0 instance Arity f => Arity ((->) a f) where arity f = 1 + arity (f…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
37
votes
1 answer

What is Haskell missing for totality checking?

A total (functional) language is one in which everything can be shown to terminate. Obviously, there are lots of places where I don't want this - throwing exceptions is sometimes handy, a web-server isn't supposed to terminate, etc. But sometimes, I…
Alec
  • 31,829
  • 7
  • 67
  • 114
37
votes
1 answer

Debugging a memory leak that doesn't show on heap profiling

I'm working on a Haskell daemon that receives and processes JSON requests. While the operations of the daemon are complex, the main structure is intentionally kept simple: Its internal state is just an IORef with a data structure and all threads…
Petr
  • 62,528
  • 13
  • 153
  • 317
36
votes
1 answer

What are the pitfalls of using FlexibleContexts and FlexibleInstances?

Since these flexible contexts and instances aren't available in the Haskell standard, I assume there are potential problems when using them. What are they? Can they lead to some ambiguity, undecidability, overlapping instances, etc.? There is a…
Petr
  • 62,528
  • 13
  • 153
  • 317
36
votes
1 answer

Is there a list of GHC extensions that are considered 'safe'?

Occasionally, a piece of code I want to write isn't legal without at least one language extension. This is particularly true when trying to implement ideas in research papers, which tend to use whichever spiffy, super-extended version of GHC was…
Chris Taylor
  • 46,912
  • 15
  • 110
  • 154
35
votes
4 answers

What is a good way to debug haskell code?

I have used the ghci debugger but would really prefer if it was somewhat integrated with a text editor to simplify the process of setting breakpoints. It should probably not strictly evaluate every visible variable but at least simplify the process…
user53067
35
votes
2 answers

Building with runtime flags using cabal and ghc

I have a program written in Haskell and intended to be compiled with GHC. The program scales very well on multiple cores, so enabling multithreading is very important. In my .cabal file I've added ghc-options: -O3 -threaded to link with the threaded…
Viktor Dahl
  • 1,942
  • 3
  • 25
  • 36
35
votes
2 answers

Make GHC only type-check?

Is there a way, either standard, or a clever hack, to make invoking GHC on a file only run the type-checker? E.g. $ ghc --just-check-the-types x.hs $ No output files, no .hi or .o, etc. Don't want to/can't use the GHC API. Just talking about the…
Christopher Done
  • 5,886
  • 4
  • 35
  • 38
34
votes
2 answers

How to relate to type from outer context

Let us consider the following code snippet: blah :: a -> b -> a blah x y = ble x where ble :: b -> b ble x = x This compiles fine under GHC, which essentially means that b from the 3rd line is something different than b from the first line.…
julx
  • 8,694
  • 6
  • 47
  • 86
34
votes
1 answer

What is ARR_WORDS in a GHC heap profile?

The heap profile for my program, generated by ./program +RTS -hy -p, is dominated by "ARR_WORDS". It doesn't correspond to anything obvious in my program; is it a GHC internal of some sort? How should I treat its dominating appearance in the…
gspr
  • 11,144
  • 3
  • 41
  • 74
34
votes
2 answers

What is the relationship between ghc-pkg and cabal?

With respect to how packages are created, installed and used in Haskell, what is the relationship between ghc-pkg and cabal? What are their roles - when would you use one, over the other, or use both? Are they complementary tools, competitive tools,…
Ben Lever
  • 2,023
  • 7
  • 26
  • 34
33
votes
1 answer

Haskell Error - Naked Expression at Top Level

I have the following code: fib n | n == 0 = 0 | n == 1 = 1 | n > 1 = fib (n-1) + fib (n-2) print fib 5 And for some reason, it's throwing an error: [1 of 1] Compiling Main ( test.hs, test.o ) test.hs:8:1: Parse error:…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
33
votes
1 answer

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 the haskell code. Unlike GCC were each label is…
haskelline
  • 1,116
  • 7
  • 15
33
votes
1 answer

How can I disable Haskell warning in small block?

I want to disable warning only some block of code. I searched Google but only find file scope or global scope disable method. Using cabal file or pragma {-# OPTIONS_GHC #-} Can I disable warning for specific function?
juhyung park
  • 503
  • 4
  • 8
33
votes
1 answer

Excessive mysterious system time use in a GHC-compiled binary

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…
Carl
  • 26,500
  • 4
  • 65
  • 86