ghc

Making sense from GHC profiler

可紊 提交于 2019-11-29 09:54:49
问题 I'm trying to make sense from GHC profiler. There is a rather simple app, which uses werq and lens-aeson libraries, and while learning about GHC profiling, I decided to play with it a bit. Using different options ( time tool, +RTS -p -RTS and +RTS -p -h ) I acquired entirely different numbers of my memory usage. Having all those numbers, I'm now completely lost trying to understand what is going on, and how much memory the app actually uses. This situation reminds me the phrase by Arthur

Using cabal with multiple GHC versions

南笙酒味 提交于 2019-11-29 09:14:06
I got both ghc6 and ghc7 on my desktop. To install new packages (for the specific ghc version), I use cabal with the flag --with-compiler=<ghc-dir> to specify for which ghc i want the package installed. I do cabal update before installing any new package. But how to I specify for which ghc I want the update? I mean, there is no --with-compiler flag as with cabal install . I would think that just like I use ghc-pkg7 for ghc7, there would be cabal7 . Apart from the cabal install command which I know to which ghc version it is applying, I don't know which ghc is affected with the other cabal

Are Haskell FlexibleInstances a stable extension to the language?

心已入冬 提交于 2019-11-29 09:05:17
What is the problem with FlexibleInstances in Haskell? Why are they not included in Haskell 2010? Were implementations of FlexibleInstances simply not stable enough for inclusion into a standard or are deeper concerns connected to FlexibleInstances? Is it safe to use them? Will they likely be included in Haskell Prime? Is it safe to use them? Yes. FlexibleInstances will not create an ambiguous or overlapping situation when GHC needs to resolve type classes. Note that the potential for overlap of the instances is possible and not an error, but any actual confusing usage during type checking

How do you write rewrite rules for typeclass methods?

半世苍凉 提交于 2019-11-29 07:31:32
问题 Mind the following class: class ListIsomorphic l where toList :: l a -> [a] fromList :: [a] -> l a I also demand that toList . fromList == id . How do I write rewrite rules to tell GHC to make that substitution? 回答1: You can use a RULES pragma to implement this simplification but you have to do a bit of extra work to make sure the generic method rewrite rules don't fire before yours have a chance to: {-# RULES "protect toList" toList = toList'; "protect fromList" fromList = fromList';

How are variable names chosen in type signatures inferred by GHC?

耗尽温柔 提交于 2019-11-29 07:14:42
When I play with checking types of functions in Haskell with :t , for example like those in my previous question , I tend to get results such as: Eq a => a -> [a] -> Bool (Ord a, Num a, Ord a1, Num a1) => a -> a1 -> a (Num t2, Num t1, Num t, Enum t2, Enum t1, Enum t) => [(t, t1, t2)] It seems that this is not such a trivial question - how does the Haskell interpreter pick literals to symbolize typeclasses? When would it choose a rather than t ? When would it choose a1 rather than b ? Is it important from the programmer's point of view? The names of the type variables aren't significant. The

How does GHCi pick names for type variables?

人走茶凉 提交于 2019-11-29 06:09:21
When using the interactive GHC interpreter, it's possible to ask for the inferred type of an expression: Prelude> :t map map :: (a -> b) -> [a] -> [b] It seems that it takes the names of the type variables from the signature since map is defined as map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs in the Prelude. That makes a lot of sense! My question is: how are type variable names picked when there is no signature given? An example would be Prelude> :t map fst map fst :: [(b, b1)] -> [b] where it picked names b and b1 . It's clear that renaming must take place, but

Haskell dynamic library

雨燕双飞 提交于 2019-11-29 04:17:09
http://www.vex.net/~trebla/haskell/so.xhtml describes how to compile shared library. About compiling command: ghc -O2 -dynamic -shared -fPIC -o libEval.so Eval.hs hsbracket.c -lHSrts-ghc7.6.3 it says: (Could you omit -dynamic to request static libraries of other packages? Not really, they were not generated with -fPIC. In particular it is illegal on x86_64.) Why is it so? What should one do to compile shared library without libHS* dependencies? Since Kaiko contacted me privately for an answer, might as well post it here... Short version By omitting -dynamic you would be trying to take all the

How does GHC/Haskell decide what character encoding it's going to decode/encode from/to?

℡╲_俬逩灬. 提交于 2019-11-29 03:49:01
It seems that GHC is at least inconsistent in the character encoding it decides to decode from. Consider a file, omatase-shimashita.txt , with the following content, encoded in UTF-8: お待たせしました readFile seems to read this in properly... Prelude> content <- readFile "/home/chris/Desktop/omatase-shimashita.txt" Prelude> length content 8 Prelude> putStrLn content お待たせしました However, if I write a simple "echo" server, it does not decode with a default of UTF-8. Consider the following code that handles an incoming client: handleClient handle = do line <- hGetLine handle putStrLn $ "Read following line

Under what circumstances could Common Subexpression Elimination affect the laziness of a Haskell program?

北战南征 提交于 2019-11-29 03:42:58
From wiki.haskell.org : First of all, common subexpression elimination (CSE) means that if an expression appears in several places, the code is rearranged so that the value of that expression is computed only once. For example: foo x = (bar x) * (bar x) might be transformed into foo x = let x' = bar x in x' * x' thus, the bar function is only called once. (And if bar is a particularly expensive function, this might save quite a lot of work.) GHC doesn't actually perform CSE as often as you might expect. The trouble is, performing CSE can affect the strictness/laziness of the program. So GHC

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

南笙酒味 提交于 2019-11-29 03:41:20
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 problem is [ALT] + [PRINT] + [K]. My question: Is there an easy way to limit the memory, which can be consumed by ghci to, let's say 1 GB? If limit is exceed, the calculation should ve aborted or ghci should be killed. Bas Bossink A platform independant way to