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
33
votes
6 answers

Haskell: read input character from console immediately, not after newline

I've tried this: main = do hSetBuffering stdin NoBuffering c <- getChar but it waits until the enter is pressed, which is not what I want. I want to read the character immediately after user presses it. I am using ghc v6.12.1 on Windows…
Steves
  • 2,798
  • 21
  • 21
33
votes
7 answers

Distributing a Haskell program as C source

Say I have a Haskell program or library that I'd like to make accessible to non-Haskellers, potentially C programmers. Can I compile it to C using GHC and then distribute this as a C source? If this is possible, can someone provide a minimal…
Steve
  • 8,153
  • 9
  • 44
  • 91
32
votes
1 answer

Get evaluation timings in GHCi

I have a relatively slow procedure (aptly named slow), and I would like to do something like time $ slow [1,2,3,4,5] in the console (REPL) to get the time, instead of having to compile the program and then run time. Can this be done?
Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93
31
votes
3 answers

Installing ghc binaries on Linux (can't find libgmp.so)

I am trying to install the Haskell Platform on Linux for the first time (I'm also a fairly new Linux user). The victim system is a fresh Red Hat system. And everything involved here should be 64 bit. The directions at the platform website [1]…
Tim
  • 2,708
  • 1
  • 18
  • 32
31
votes
2 answers

What IO activity does the GHC IO manager support?

I've been reading about the new IO manager in GHC, which uses asynchronous event notifications and eschews blocking I/O to achieve high throughput. Which IO activities are eligible for management by the new asynchronous IO code? Reading and writing…
Bill
  • 44,502
  • 24
  • 122
  • 213
31
votes
3 answers

Can a `ST`-like monad be executed purely (without the `ST` library)?

This post is literate Haskell. Just put in a file like "pad.lhs" and ghci will be able to run it. > {-# LANGUAGE GADTs, Rank2Types #-} > import Control.Monad > import Control.Monad.ST > import Data.STRef Okay, so I was able to figure how to…
PyRulez
  • 10,513
  • 10
  • 42
  • 87
30
votes
4 answers

How to [temporarily] suppress "defined but not used" warnings?

When I prototype Haskell programs, I always get hundreds of warnings like this (not joking): /Users/bob/SourceCode/course/is/expriment/LiftedSpine2.hs:70:15: Warning: Defined but not used:…
bobzhang
  • 1,771
  • 3
  • 17
  • 19
30
votes
1 answer

Using Emoji in Haskell

I've recently come across a bot on Twitter named EmojiHaskell, that claims to tweet 'interpretable Haskell code with emoji variable names'. A particular Tweet caught my attention, as it looked like malformed syntax to me, so I decided to take a…
Jakob Runge
  • 2,287
  • 7
  • 36
  • 47
30
votes
2 answers

Using Sublime 2 for Haskell Development?

What is the current status of Sublime 2 integration for Haskell? I see two possible packages so far. A plugin for code highlighting and a REPL plugin. Is there an intelli-sense plugin for Haskell? Maybe integration with Hackage as well? Thanks.
The Internet
  • 7,959
  • 10
  • 54
  • 89
29
votes
2 answers

Are there any advantages of using Rank2Types in favor of RankNTypes?

As far as I know, a decidable type checking algorithm exists (only) for rank-2 types. Does GHC use somehow this fact, and does it have any practical implications? Is there also a notion of principal types for rank-2 types, and a type inference…
Petr
  • 62,528
  • 13
  • 153
  • 317
29
votes
1 answer

Can using UndecidableInstances pragma locally have global consequences on compilation termination?

Suppose a Haskell library designer decides to use UndecidableInstances for some reason. The library compiles fine. Now suppose some program uses the library (like defines some instances of its type classes), but doesn't use the extension. Can it…
Petr
  • 62,528
  • 13
  • 153
  • 317
29
votes
3 answers

Why is GHC complaining about non-exhaustive patterns?

When I compile the following code with GHC (using the -Wall flag): module Main where data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) insert :: (Ord a) => a -> Tree a -> Tree a insert x EmptyTree = Node x EmptyTree…
Alexandros
  • 3,044
  • 1
  • 23
  • 37
28
votes
3 answers

Can GHC really never inline map, scanl, foldr, etc.?

I've noticed the GHC manual says "for a self-recursive function, the loop breaker can only be the function itself, so an INLINE pragma is always ignored." Doesn't this say every application of common recursive functional constructs like map, zip,…
Jeff Burdges
  • 4,204
  • 23
  • 46
28
votes
4 answers

LLVM vs. C-- ; how can LLVM fundamentally not be better for Haskell than C--?

I've been excited about LLVM being low enough to model any system, and saw it as promising that Apple was adopting it; but then again Apple doesn't specifically support Haskell; And, some think that Haskell would be better off with C--: That…
dr.addn
  • 423
  • 4
  • 7
28
votes
7 answers

How to make a CAF not a CAF in Haskell?

How do I make a Constant Applicative Form into, well, not a Constant Applicative Form, to stop it being retained for the lifetime of the program? I've tried this approach: -- | Dummy parameter to avoid creating a CAF twoTrues :: () ->…
Robin Green
  • 32,079
  • 16
  • 104
  • 187