ghc

How do I get the OverloadedStrings language extension working?

末鹿安然 提交于 2019-12-05 08:50:14
问题 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, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading

Profiling/Improving memory usage and/or GC time

不羁岁月 提交于 2019-12-05 08:48:29
Original I'm trying to aggregate a CSV file and experiencing [what I consider to be] excessive memory usage and/or GC effort. The issue seems to arise when the number of groups increases. There is no problem when the keys are in the hundreds or thousands, but quickly starts spending a majority of time in the GC when the keys reach tens of thousands. Update Moving from Data.ByteString.Lazy.ByteString to Data.ByteString.Short.ShortByteString significantly reduced the memory consumption (to a level I think is reasonable). However, the amount of time spent in the GC still seems far higher than I

How to force GHC to inline FFI calls?

和自甴很熟 提交于 2019-12-05 07:54:32
I made small C module to improve performance, but GHC doesn't inline foreign functions, and calls cost eliminates the acceleration. For example, test.h : int inc (int x); test.c : #include "test.h" int inc(int x) {return x + 1;} Test.hc : {-# LANGUAGE ForeignFunctionInterface #-} module Test (inc) where import Foreign import Foreign.C foreign import ccall unsafe "test.h inc" c_inc :: CInt -> CInt inc = fromIntegral . c_inc . fromIntegral {-# INLINE c_inc #-} {-# INLINE inc #-} Main.hs : import System.Environment import Test main = do {args <- getArgs; putStrLn . show . inc . read . head $ args

Is there a way to only compile Haskell source to interface file, not further? [duplicate]

独自空忆成欢 提交于 2019-12-05 07:06:53
This question already has answers here : Haskell: How to only generate .hi file with ghc? (2 answers) Closed last year . Usually, when ghc is compiling a source code, it will produce at least an .o (object) and a .hi (interface) file. In the interest of diminishing compilation time, if I only need an interface file, can I somehow order ghc to abandon everything else and just give me said interface file? Or, otherwise, obtain that interface by any kind of lowly guile? I found this ghc user guide part and it says nothing of such. This one doesn't even mention " interface " anywhere in its text.

Haskell GHC Dynamic Compliation Only works on first compile

谁都会走 提交于 2019-12-05 07:05:33
Following the GHC tutorial posted here and alterations to this code following the advice in a previous stack overflow question I asked , I have created a program which is able to compile and run a module in Test.hs with a function print to print a string to the screen: import GHC import GHC.Paths import DynFlags import Unsafe.Coerce main :: IO () main = defaultErrorHandler defaultLogAction $ do func <- runGhc (Just libdir) $ do dflags <- getSessionDynFlags setSessionDynFlags dflags target <- guessTarget "Test.hs" Nothing addTarget target r <- load LoadAllTargets case r of Failed -> error

Type Inference in Patterns

老子叫甜甜 提交于 2019-12-05 06:47:00
I noticed that GHC wanted a type signature which I think should be inferred. I minimized my example down to this, which almost certainly does nothing meaningful (I don't recommend running it on your favorite types): {-# LANGUAGE GADTs, RankNTypes, ScopedTypeVariables, TypeOperators, NoMonomorphismRestriction #-} module Foo where import Data.Typeable data Bar rp rq data Foo b = Foo (Foo b) rebar :: forall rp rq rp' rp'' . (Typeable rp', Typeable rp'') => Proxy rp' -> Proxy rp'' -> Foo rp -> Foo (Bar rp rq) rebar p1 p2 (Foo x) = -- The signature for y should be inferred... let y = rebar p1 p2 x

Bytestring linking in ghc

我只是一个虾纸丫 提交于 2019-12-05 06:30:36
Consider the following simple code: import Crypto.Hash.SHA1 (hashlazy) import qualified Data.ByteString as BS main = return () I installed cabal install --global bytestring and then I obtain (on a newly installed Ubuntu 12.04 machine using ghc 7.4.1): GHCi runtime linker: fatal error: I found a duplicate definition for symbol fps_minimum whilst processing object file /usr/local/lib/bytestring-0.10.0.1/ghc-7.4.1/HSbytestring-0.10.0.1.o This could be caused by: * Loading two different object files which export the same symbol * Specifying the same object file twice on the GHCi command line * An

GHC package is hidden

為{幸葍}努か 提交于 2019-12-05 05:46:30
I'm trying to run this simple example that I got from the Haskell wiki . import GHC import GHC.Paths ( libdir ) import DynFlags main = defaultErrorHandler defaultFatalMessager defaultFlushOut $ do runGhc (Just libdir) $ do dflags <- getSessionDynFlags setSessionDynFlags dflags target <- guessTarget "test_main.hs" Nothing setTargets [target] load LoadAllTargets The error messages I'm getting are: amy@wombat$ ghc --make amy15.hs amy15.hs:1:8: Could not find module ‘GHC’ It is a member of the hidden package ‘ghc-7.8.3’. Use -v to see a list of the files searched for. amy15.hs:3:8: Could not find

How can I get GHC to generate instances of Data.Typeable for GADTs with Typeable in the context?

穿精又带淫゛_ 提交于 2019-12-05 05:12:48
Suppose I have the following code: {-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-} import Data.Typeable class Eq t => OnlyEq t class (Eq t, Typeable t) => BothEqAndTypeable t data Wrapper a where Wrap :: BothEqAndTypeable a => a -> Wrapper a deriving instance Eq (Wrapper a) deriving instance Typeable1 Wrapper Then, the following instance declaration works, without a constraint on t : instance OnlyEq (Wrapper t) and does what I expect it to do. But the following instance declaration doesn't work: instance BothEqAndTypeable (Wrapper t) since GHC - I'm using 7.6.1 - complains that:

What caused this “delayed read on closed handle” error?

家住魔仙堡 提交于 2019-12-05 05:09:42
I just installed GHC from the latest sources, and now my program gives me an error message about a "delayed read on closed handle". What does this mean? dfeuer The fundamental lazy I/O primitive, hGetContents , produces a String lazily—it only reads from the handle as needed to produce the parts of the string your program actually demands. Once the handle has been closed, however, it is no longer possible to read from the handle, and if you try to inspect a part of the string that was not yet read, you will get this exception. For example, suppose you write main = do most <- withFile "myfile"