ghc

How does the Haskell compiler handle the 'where' statement?

In the following function, I'm wondering if the compiler is clever enough to work out that x is going to remain constant, or will it compute the head of the list for every item in the list? (I'm using GHC) allSame :: Eq a => [a] -> Bool allSame xs = all (==x) xs where x = head xs ...

Of which things should I take care if I'm using unboxed type (like Int#) in Haskell / GHC?

I'm trying to write a small script which parses and executes Brainfuck code, to understand the GHC options of optimization, I'm trying to optimize the code in order to be a bit faster and to understand what's going on there. On of the parts is the internal represantation of BF-code, I use a special datatype for this. Here's the sourceco...

convert do notation to bind function

Hi I know that the following "do" notation's "bind" function is equivalent to getLine >>= \line -> putStrLn do line <- getLine putStrLn line But how is the following notation equivalent to bind function? do line1 <- getLine putStrLn "enter second line" line2 <- getLine return (line1,line2) ...

Is there a way to limit the memory, ghci can have?

I'm used to debug my code using ghci. Often, something like this happens (not so obvious, of course): ghci> let f@(_:x) = 0:1:zipWith(+)f x ghci> length f Then, nothing happens for some time, and if I don't react fast enough, ghci has eaten maybe 2 GB of RAM, causing my system to freeze. If it's too late, the only way to solve this pr...

How do I get the OverloadedStrings language extension working?

I've enabled overloaded strings, but I can't get them to work: $ cat overloadedstrings.hs {-# LANGUAGE OverloadedStrings #-} import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL lazy :: BL.ByteString lazy = "I'm a lazy ByteString" strict :: B.ByteString strict = "I'm a strict ByteString" $ ghci GHCi, ve...

Why am I getting this warning from GHCi?

I'm getting a curious warning when pattern matching, but only when OverloadedStrings is enabled... $ ghci -Wall GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> let f x = case...

Is it possible to use the GHC API to modify a program while compiling it?

I want to test the implementation a compiler optimization by piggybacking into the GHC compilation process and altering its Core representation. The idea would be to have something like: runGhc (Just libdir) $ do ... c <- compileToCoreModule targetFile compileCoreToObj False (modify c) ... where modify takes the Core repre...

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 calls (presumably it caches the list), whereas m2 10000000 always takes the same amount of...

How do I link modules in ghc?

I have a haskell program that uses Data.Set and Data.IntMap, what flags do I need to give GHC to get it to link those libraries in? Simple question, I know, but the man pages didn't help me and I don't know where to look. ...

How to use fromInteger with no implicit prelude in Haskell?

The following program yields an error in ghci: {-# LANGUAGE NoImplicitPrelude #-} import Prelude (Integer, Bool) import qualified Prelude class Discrete a where (==) :: a -> a -> Bool instance Discrete Integer where (==) = (Prelude.==) class Monoid a where one :: a (*) :: a -> a -> a fromInteger :: Integer -> a ...

Is DeriveFunctor a well-recognized extension? Cabal seems confused.

Cabal is giving me mixed messages. When I say: Extensions: DeriveFunctor It says: Warning: Unknown extensions: DeriveFunctor But when I say: GHC-Options: -XDeriveFunctor It says: Warning: Instead of 'ghc-options: -XDeriveFunctor' use 'extensions: DeriveFunctor' For now I'm just going to use the {#- LANGUAGE DeriveFunctor -#} ...

Understanding GHC error "Qualified name in binding position"

If I create a module AModule with a typeclass Foo, module AModule where class Foo a where bar :: a and in another module BModule import AModule qualified and try to make some type an instance of Foo, i.e. module B where import qualified AModule as A instance A.Foo Int where A.bar = 0 GHC tells me "Qualified name in binding po...

xmonad could not find module `XMonad': broken package

Hi my Xmonad has been working perfectly until few days ago, then I think I installed something with Synaptic and then started to complain about Xmonad.Config.Gnome here it is my xmonad.hs import XMonad import XMonad.Config.Gnome myManageHook = composeAll [ (className =? "Pidgin" <&&> title =? "Buddy List") --> doFloat ...