ghc

Difference between print and putStrLn in Haskell

天大地大妈咪最大 提交于 2019-11-28 18:22:24
问题 I am confused. I tried to use print , but I know people apply putStrLn . What are the real differences between them? print $ function putStrLn $ function 回答1: The function putStrLn takes a String and displays it to the screen, followed by a newline character ( put a Str ing followed by a new L i n e). Because it only works with String s, a common idiom is to take any object, convert it to a String , and then apply putStrLn to display it. The generic way to convert an object to a String is

How to execute a command right after a fetch or pull command in git?

我的未来我决定 提交于 2019-11-28 17:51:58
I cloned the GHC (Glasgow Haskell Compiler) repository. In order to build the compiler, you need several libraries, all of them are available as git repositories too. In order to ease ones live, the GHC hackers included a script sync-all that, when executed, updates all the dependent repositories. Now to my question: How can I make git execute ./sync-all pull after I did a git pull automatically? I heard something about using hooks, but I don't really know, what I have to do. If you need to execute a script after a git pull on the client side (your machine), then a there is no reliable

Laziness and tail recursion in Haskell, why is this crashing?

感情迁移 提交于 2019-11-28 17:36:39
I have this fairly simple function to compute the mean of elements of a big list, using two accumulators to hold the sum so far and the count so far: mean = go 0 0 where go s l [] = s / fromIntegral l go s l (x:xs) = go (s+x) (l+1) xs main = do putStrLn (show (mean [0..10000000])) Now, in a strict language, this would be tail-recursive, and there would be no problem. However, as Haskell is lazy, my googling has led me to understand that (s+x) and (l+1) will be passed down the recursion as thunks. So this whole thing crashes and burns: Stack space overflow: current size 8388608 bytes. After

Fixing issues noted by ghc-pkg check

Deadly 提交于 2019-11-28 17:12:18
It's rather nice that ghc-pkg check will list broken packages, and why they are broken. But as far as I know, there is no automated way to take care of those broken packages. What is the recommended way to deal with broken packages? (Preferably not reinstall GHC) Hopefully, you have been wise enough to not break any in your global package database. Breakage there can easily mean a reinstallation of GHC is necessary. So, let us assume that the breakage is restricted to the user package db (except possibly a package or two in the global shadowed by user packages). If only few packages are broken

Specialization with Constraints

心不动则不痛 提交于 2019-11-28 16:46:01
I'm having problems getting GHC to specialize a function with a class constraint. I have a minimal example of my problem here: Foo.hs and Main.hs . The two files compile (GHC 7.6.2, ghc -O3 Main ) and run. NOTE: Foo.hs is really stripped down. If you want to see why the constraint is needed, you can see a little more code here . If I put the code in a single file or make many other minor changes, GHC simply inlines the call to plusFastCyc . This will not happen in the real code because plusFastCyc is too large for GHC to inline, even when marked INLINE . The point is to specialize the call to

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

大兔子大兔子 提交于 2019-11-28 16:43:15
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 , scan* , fold* , sum , etc. cannot be inlined? You could always rewrite all these function when you employ them, adding appropriate strictness tags, or maybe employ fancy techniques like the "stream fusion" recommended here . Yet, doesn't all this dramatically constrain our ability to write code that's simultaneously fast and elegant? Indeed, GHC

Making small haskell executables?

戏子无情 提交于 2019-11-28 16:40:15
Are there any good ways to make small haskell executables? With ghc6 a simple hello world program seems to come to about 370kB (523kB before strip). Hello world in C is about 4kB (9kB before strip). Caleb Case With the development branch of GHC (anyone know exactly which version this was added in?): $ ghc -o hello hello.hs $ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello $ du hello hello-small 700 hello 476 hello-small Add the -dynamic flag for a dynamically linked RTS: $ ghc -dynamic -o hello hello.hs $ strip -p --strip-unneeded --remove-section=.comment -o hello

Curious about the HashTable performance issues

北城余情 提交于 2019-11-28 16:29:58
I read that hash tables in Haskell had performance issues (on the Haskell-Cafe in 2006 and Flying Frog Consultancy's blog in 2009), and since I like Haskell it worried me. That was a year ago, what is the status now (June 2010)? Has the "hash table problem" been fixed in GHC? The problem was that the garbage collector is required to traverse mutable arrays of pointers ("boxed arrays") looking for pointers to data that might be ready to deallocate. Boxed, mutable arrays are the main mechanism for implementing a hashtable, so that particular structure showed up the GC traversal issue. This is

Everywhere that GHC/Haskell Platform installs

╄→гoц情女王★ 提交于 2019-11-28 16:24:15
Assume I want to completely reinstall GHC/HP. I want to (as much for superstition as anything) delete anything and everything from previous installs. What do I actually need to delete (and where)? Edit: I'm on OSX, but I'm more curious if this information is available in general, for all systems. Edit2: So far we have: OSX: /Library/Frameworks/GHC.framework/ ~/.cabal/ /usr/bin/ -- symlinks I'll add to that (based on "prefix" defined here: http://www.vex.net/~trebla/haskell/sicp.xhtml#storage ): prefix/lib/ prefix/share/ prefix/bin/ prefix/share/doc/ /usr (/local) /lib/[ghc-version] /usr (

Why can I not make String an instance of a typeclass?

匆匆过客 提交于 2019-11-28 16:02:35
Given : data Foo = FooString String … class Fooable a where --(is this a good way to name this?) toFoo :: a -> Foo I want to make String an instance of Fooable : instance Fooable String where toFoo = FooString GHC then complains: Illegal instance declaration for `Fooable String' (All instance types must be of the form (T t1 ... tn) where T is not a synonym. Use -XTypeSynonymInstances if you want to disable this.) In the instance declaration for `Fooable String' If instead I use [Char] : instance Fooable [Char] where toFoo = FooString GHC complains: Illegal instance declaration for `Fooable