ghc

Orphaned instances in Haskell

夙愿已清 提交于 2019-11-27 09:20:35
问题 When compiling my Haskell application with the -Wall option, GHC complains about orphaned instances, for example: Publisher.hs:45:9: Warning: orphan instance: instance ToSElem Result The type class ToSElem is not mine, it's defined by HStringTemplate. Now I know how to fix this (move the instance declaration into the module where Result is declared), and I know why GHC would prefer to avoid orphaned instances, but I still believe that my way is better. I don't care if the compiler is

Why is GHC so large/big?

我怕爱的太早我们不能终老 提交于 2019-11-27 09:18:51
问题 Is there a simple answer: Why is GHC so big? OCaml: 2MB Python: 15MB SBCL: 9MB OpenJRE - 26MB GHC: 113MB Not interested in evangelism of "Why I shouldn't care about the size if Haskell is the right tool"; this is a technical question. 回答1: It's a bit silly really. Every library that comes with GHC is provided in no less than 4 flavours : static dynamic profiled GHCi The GHCi version is just the static version linked together in a single .o file. The other three versions all have their own set

How to make a CAF not a CAF in Haskell?

时间秒杀一切 提交于 2019-11-27 07:16:00
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 to Neil Mitchell who asked precisely this question - but that answer refers to a dead link, unfortunately.

Why is GHC complaining about non-exhaustive patterns?

喜欢而已 提交于 2019-11-27 03:45:44
问题 When I compile the following code with GHC (using the -Wall flag): module Main where data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) insert :: (Ord a) => a -> Tree a -> Tree a insert x EmptyTree = Node x EmptyTree EmptyTree insert x (Node a left right) | x == a = Node a left right | x < a = Node a (insert x left) right | x > a = Node a left (insert x right) main :: IO() main = do let nums = [1..10]::[Int] print . foldr insert EmptyTree $ nums GHC complains that pattern

Haskell Space Overflow

狂风中的少年 提交于 2019-11-27 03:31:04
问题 I've compiled this program and am trying to run it. import Data.List import Data.Ord import qualified Data.MemoCombinators as Memo collatzLength :: Int -> Int collatzLength = Memo.arrayRange (1, 1000000) collatzLength' where collatzLength' 1 = 1 collatzLength' n | odd n = 1 + collatzLength (3 * n + 1) | even n = 1 + collatzLength (n `quot` 2) main = print $ maximumBy (comparing fst) $ [(collatzLength n, n) | n <- [1..1000000]] I'm getting the following from GHC Stack space overflow: current

Using GHC API to compile Haskell sources to CORE and CORE to binary

北战南征 提交于 2019-11-27 02:36:19
问题 The Idea Hello! I want to create a program, that will generate Haskell Core and will use GHC API to compile it further into an executable. But before I will do it I want to construct a very basic example, showing how can we just compile Haskell sources into CORE and then into the binary file. The problem I have read a lot of documentation and tried many methods from GHC Api, but for now without success. I started with Official GHC Api introduction and successfully compiled the examples. The

Haskell: read input character from console immediately, not after newline

送分小仙女□ 提交于 2019-11-27 02:31:52
问题 I've tried this: main = do hSetBuffering stdin NoBuffering c <- getChar but it waits until the enter is pressed, which is not what I want. I want to read the character immediately after user presses it. I am using ghc v6.12.1 on Windows 7. EDIT: workaround for me was moving from GHC to WinHugs, which supports this correctly. 回答1: Might be a bug: http://hackage.haskell.org/trac/ghc/ticket/2189 The following program repeats inputted characters until the escape key is pressed. import IO import

Debugging infinite loops in Haskell programs with GHCi

Deadly 提交于 2019-11-27 02:08:28
问题 For the first time I've encountered an infinite loop in a Haskell program I'm writing. I've narrowed it down to a quite specific section of code, but I cannot seem to pinpoint exactly where I have a non-terminating recursive definition. I'm vaguely familiar with :trace and :history in GHCi, but the problem is that some branches of my code involve quite a bit of recursive modifications of a Data.Map.Map in the sense that the map x is obtained by adjust ing something in the map x' based on

Preferred method for viewing code generated by Template Haskell

折月煮酒 提交于 2019-11-27 01:13:35
问题 As you know, Template Haskell is used to generate various kinds of AST splices programmatically at compile-time. However, a splice can often be very opaque, and it is often difficult to discern what a splice actually generates. If you run the Q monad for a splice, and the splice is well-typed, you get a show able representation of the generated piece of AST, but this representation can be very difficult to understand, because of its unstructured layout. What is the preferred method for

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

Deadly 提交于 2019-11-27 00:43:12
问题 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. 回答1: If you need