ghc

How to make a CAF not a CAF in Haskell?

喜欢而已 提交于 2019-11-26 13:08:55
问题 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 :: () -> [[[Bool]]] twoTrues _ = map (++ (True : repeat False)) . trueBlock <$> [1..] but it doesn\'t seem to work - the profile shows it as still being retained and still marks it as a CAF. I\'ve found one relevant Google result on this, a reply by Simon Peyton-Jones

Reading GHC Core

杀马特。学长 韩版系。学妹 提交于 2019-11-26 11:26:07
Core is GHC's intermediate language. Reading Core can help you better understand the performance of your program. Someone asked me for documentation or tutorials on reading Core, but I couldn't find much. What documentation is available for reading GHC Core? Here's what I've found so far: Write Haskell as fast as C: exploiting strictness, laziness and recursion Haskell as fast as C: working at a high altitude for low level performance RWH: Chapter 25. Profiling and optimization High-Performance Haskell talk at CUFP (slide 65-80) Don Stewart GHC Core is the System FC language into which all

When is memoization automatic in GHC Haskell?

不打扰是莪最后的温柔 提交于 2019-11-26 10:13:22
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 time (rebuilding the list with each call). Any idea what's going on? Are there any rules of thumb as to if and when GHC will memoize a function? Thanks. GHC does not memoize functions. It does, however, compute any given expression in the code at most once per time that

Memory footprint of Haskell data types

若如初见. 提交于 2019-11-26 10:13:15
How can I find the actual amount of memory required to store a value of some data type in Haskell (mostly with GHC)? Is it possible to evaluate it at runtime (e.g. in GHCi) or is it possible to estimate memory requirements of a compound data type from its components? In general, if memory requirements of types a and b are known, what is the memory overhead of algebraic data types such as: data Uno = Uno a data Due = Due a b For example, how many bytes in memory do these values occupy? 1 :: Int8 1 :: Integer 2^100 :: Integer \x -> x + 1 (1 :: Int8, 2 :: Int8) [1] :: [Int8] Just (1 :: Int8)

What does the `forall` keyword in Haskell/GHC do?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 08:38:37
问题 I\'m beginning to understand how the forall keyword is used in so-called \"existential types\" like this: data ShowBox = forall s. Show s => SB s This is only a subset, however, of how forall is used and I simply cannot wrap my mind around its use in things like this: runST :: forall a. (forall s. ST s a) -> a Or explaining why these are different: foo :: (forall a. a -> a) -> (Char, Bool) bar :: forall a. ((a -> a) -> (Char, Bool)) Or the whole RankNTypes stuff... I tend to prefer clear,

Wrong IO actions order using putStr and getLine

帅比萌擦擦* 提交于 2019-11-26 07:38:07
问题 I have the following code: main = do putStr \"Test input : \" content <- getLine putStrLn content When I run it (with runhaskell ) or compile it (ghc 6.10.4) the result is like this: asd Test input : asd Why is Test input : asd being printed after asd ? In the code sample on http://learnyouahaskell.com/, which uses putStr , the getLine \'s presented output is different than mine. When I use putStrLn the program works as expected (print, then prompt, and print). Is it a bug in ghc , or it is

Small Haskell program compiled with GHC into huge binary

扶醉桌前 提交于 2019-11-26 04:06:01
问题 Even trivially small Haskell programs turn into gigantic executables. I\'ve written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB! What can cause even a small Haskell program to be compiled to the huge binary? What, if anything, can I do to reduce this? 回答1: Let's see what's going on, try $ du -hs A 13M A $ file A A: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped $ ldd A

Reading GHC Core

喜你入骨 提交于 2019-11-26 03:31:29
问题 Core is GHC\'s intermediate language. Reading Core can help you better understand the performance of your program. Someone asked me for documentation or tutorials on reading Core, but I couldn\'t find much. What documentation is available for reading GHC Core? Here\'s what I\'ve found so far: Write Haskell as fast as C: exploiting strictness, laziness and recursion Haskell as fast as C: working at a high altitude for low level performance RWH: Chapter 25. Profiling and optimization High

When is memoization automatic in GHC Haskell?

蹲街弑〆低调 提交于 2019-11-26 02:05:59
问题 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 time (rebuilding the list with each call). Any idea what\'s going on? Are there any rules of thumb as to if and when GHC will memoize a function? Thanks. 回答1: GHC does

Memory footprint of Haskell data types

China☆狼群 提交于 2019-11-26 02:05:52
问题 How can I find the actual amount of memory required to store a value of some data type in Haskell (mostly with GHC)? Is it possible to evaluate it at runtime (e.g. in GHCi) or is it possible to estimate memory requirements of a compound data type from its components? In general, if memory requirements of types a and b are known, what is the memory overhead of algebraic data types such as: data Uno = Uno a data Due = Due a b For example, how many bytes in memory do these values occupy? 1 ::