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

Future of roles for GADT-like type variables?

A question from yesterday had a definition of HList (from the HList package) that uses data families. Basically: data family HList (l :: [*]) data instance HList '[] = HNil newtype instance HList (x ': xs) = HCons1 (x, HList xs) pattern HCons x xs…
Alec
  • 31,829
  • 7
  • 67
  • 114
51
votes
3 answers

How are lists implemented in Haskell (GHC)?

I was just curious about some exact implementation details of lists in Haskell (GHC-specific answers are fine)--are they naive linked lists, or do they have any special optimizations? More specifically: Do length and (!!) (for instance) have to…
shosti
  • 7,332
  • 4
  • 37
  • 42
50
votes
3 answers

How atomic are GHC's thunks?

How does GHC handle thunks that are accessed by multiple threads (either explicit threads, or the internal ones that evaluate sparks)? Can it happen that multiple threads evaluate the same thunk, duplicating work? Or, if thunks are synchronized,…
Petr
  • 62,528
  • 13
  • 153
  • 317
48
votes
2 answers

Good introductory text about GHC implementation?

When programming in Haskell (and especially when solving Project Euler problems, where suboptimal solutions tend to stress the CPU or memory needs) I'm often puzzled why the program behaves the way it is. I look at profiles, try to introduce some…
48
votes
4 answers

What is the FlexibleContexts extension good for? Could you please explain it using a simple example?

I was trying to understand what the FlexibleContexts extension is doing by searching for web pages that would explain it to mere mortals (people who have read LYHFGG, for example, like me) but I did not find any such resource. Therefore I ask the…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
47
votes
1 answer

Is there any reason not to use the INLINABLE pragma for a function?

The documentation states: An {-# INLINABLE f #-} pragma on a function f has the following behaviour: While INLINE says "please inline me", the INLINABLE says "feel free to inline me; use your discretion". In other words the choice is left to GHC,…
glaebhoerl
  • 7,695
  • 3
  • 30
  • 41
47
votes
11 answers

Is it a good idea to compile a language to C?

All over the web, I am getting the feeling that writing a C backend for a compiler is not such a good idea anymore. GHC's C backend is not being actively developed anymore (this is my unsupported feeling). Compilers are targeting C-- or…
aelguindy
  • 3,703
  • 24
  • 31
46
votes
2 answers

Functions don't just have types: They ARE Types. And Kinds. And Sorts. Help put a blown mind back together

I was doing my usual "Read a chapter of LYAH before bed" routine, feeling like my brain was expanding with every code sample. At this point I was convinced that I understood the core awesomeness of Haskell, and now just had to understand the…
TheIronKnuckle
  • 7,224
  • 4
  • 33
  • 56
46
votes
3 answers

How to use a DLL in a Haskell project?

I would like to use an external library, RDFox, in a Haskell project. Context: I am working on Windows and Linux, both 64 bits, using GHC 7.10 and stack. RDFox is programmed in C++. RDFox shared libraries (.dll, .so) can be downloaded with Java and…
Der Vogel
  • 460
  • 3
  • 6
45
votes
3 answers

Preferred method for viewing code generated by Template Haskell

As you know, Template Haskell is used to generate various kinds of AST splices programmatically at compile-time. However, a splice can often be very opaque, and it is often difficult to discern what a splice actually generates. If you run the Q…
dflemstr
  • 25,947
  • 5
  • 70
  • 105
45
votes
1 answer

What does the GHC source mean by "zonk"?

I'm working on a plugin for GHC, so I'm reading the documentation for some of its implementation. The verb "to zonk" is all over the place, but I can't track down an explanation of what it means to zonk something or (in broad terms) when one might…
Doug McClean
  • 14,265
  • 6
  • 48
  • 70
44
votes
1 answer

Haskell tuple constructor (GHC) and the separation between a language and its implementation

Haskell blew my mind yet again when I realised that (x,y) Is just syntactic sugar for (,) x y Naturally I wanted to extend this to larger tuples. But (,) x ((,) y z) Gave me (x,(y,z)) Which was not what I was looking for. On a whim, I…
TheIronKnuckle
  • 7,224
  • 4
  • 33
  • 56
44
votes
1 answer

What is fusion in Haskell?

Every now and again I have been noticing the following in Haskell documentation: (for example in Data.Text): Subject to fusion What is fusion and how do I use it?
Abraham P
  • 15,029
  • 13
  • 58
  • 126
44
votes
3 answers

How do I determine my GHC version?

This is probably a very dumb question, but I can't seem to find the answer...
Diego Saa
  • 1,426
  • 1
  • 13
  • 23
43
votes
2 answers

Creating Haskell shared libraries on OS X

I'm trying to create a shared library from Haskell source code. I've tried following the instruction here: http://weblog.haskell.cz/pivnik/building-a-shared-library-in-haskell/ but I'm just not having any luck. When I compile with Haskell 64-bit…
benno
  • 2,077
  • 1
  • 19
  • 23