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
103
votes
3 answers

Is there a way to make GHC provide the type class constraints of typed holes?

Current behavior Prelude> show _ :7:6: Found hole ‘_’ with type: a0 Where: ‘a0’ is an ambiguous type variable Relevant bindings include it :: String (bound at :7:1) In the first argument of ‘show’, namely…
Wizek
  • 4,854
  • 2
  • 25
  • 52
90
votes
4 answers

Why can I not make String an instance of a typeclass?

Given: data Foo = FooString String … class Fooable a where --(is this a good way to name this?) toFoo :: a -> Foo I want to make String an instance of Fooable: instance Fooable String where toFoo = FooString GHC then complains: Illegal…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
89
votes
1 answer

Why does this Haskell code run slower with -O?

This piece of Haskell code runs much slower with -O, but -O should be non-dangerous. Can anyone tell me what happened? If it matters, it is an attempt to solve this problem, and it uses binary search and persistent segment tree: import…
johnchen902
  • 9,531
  • 1
  • 27
  • 69
88
votes
6 answers

Orphaned instances in Haskell

When compiling my Haskell application with the -Wall option, GHC complains about orphaned instances, for example: Publisher.hs:45:9: Warning: orphan instance: instance ToSElem Result The type class ToSElem is not mine, it's defined by…
Dan Dyer
  • 53,737
  • 19
  • 129
  • 165
85
votes
1 answer

How to read this GHC Core "proof"?

I wrote this small bit of Haskell to figure out how GHC proves that for natural numbers, you can only halve the even ones: {-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeFamilies #-} module Nat where data Nat = Z | S Nat data Parity = Even |…
Mathijs Kwik
  • 1,227
  • 9
  • 12
85
votes
4 answers

How can I uninstall a version of a Cabal package?

Happstack Lite is breaking on me because it's getting blaze-html version 0.5 and it wants version 0.4. Cabal says that both versions 0.4.3.4 and 0.5.0.0 are installed. I want to remove the 0.5.0.0 and use just the older version. But cabal does…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
83
votes
4 answers

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). I can't find the command line option on GHC to do this, though. It always wants to compile my file. Took a look at GHCi as well, but it…
Joshua Cheek
  • 30,436
  • 16
  • 74
  • 83
77
votes
4 answers

Should I use GHC Haskell extensions or not?

As I am learning Haskell, I see that there is a lot of language extensions used in real life code. As a beginner, should I learn to use them, or should I avoid them at all cost? I see that it breaks compatibility with Haskell 98 and limits code to…
sastanin
  • 40,473
  • 13
  • 103
  • 130
75
votes
1 answer

Difference between print and putStrLn in Haskell

I am confused. I tried to use print, but I know people apply putStrLn. What are the real differences between them? print $ function putStrLn $ function
Amir Nabaei
  • 1,582
  • 1
  • 15
  • 26
63
votes
1 answer

Data Constructor promotion in GHC-7.6

I had this code: class SymbolSet tpe where data Symbol tpe :: * data SSet tpe where Identity :: tpe -> SSet tpe And :: SSet tpe -> Symbol tpe -> SSet tpe class HasElem a b where instance (SymbolSet tpe) => HasElem (And (Identity tpe) s)…
rabisg
  • 731
  • 4
  • 6
63
votes
2 answers

cmm call format for foreign primop (integer-gmp example)

I have been checking out integer-gmp source code to understand how foreign primops can be implemented in terms of cmm as documented on GHC Primops page. I am aware of techniques to implement them using llvm hack or fvia-C/gcc - this is more of a…
Sal
  • 4,312
  • 1
  • 17
  • 26
58
votes
1 answer

Pragmatics of typed intermediate languages

One trend in the compilation is to use typed intermediate languages. Haskell's ghc with its core intermediate language, a variant of System F-omega, is an example of this architecture [ 1 ]. Another is LLVM, which has a typed intermediate language…
55
votes
6 answers

Mixing Erlang and Haskell

If you've bought into the functional programming paradigm, the chances are that you like both Erlang and Haskell. Both have purely functional cores and other goodness such as lightweight threads that make them a good fit for a multicore world. But…
52
votes
2 answers

Curious about the HashTable performance issues

I read that hash tables in Haskell had performance issues (on the Haskell-Cafe in 2006 and Flying Frog Consultancy's blog in 2009), and since I like Haskell it worried me. That was a year ago, what is the status now (June 2010)? Has the "hash table…
Alessandro Stamatto
  • 1,489
  • 2
  • 14
  • 18
52
votes
4 answers

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 defines how laziness is implemented. Unevaluated thunks are stored as an…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220