ghc

Orphaned instances in Haskell

牧云@^-^@ 提交于 2019-11-28 15:41:45
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 inconvenienced - rather it than me. The reason I want to declare my ToSElem instances in the Publisher module

Why is GHC so large/big?

会有一股神秘感。 提交于 2019-11-28 15:40:54
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. 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 of interface files ( .hi files) too. The profiled versions seem to be about twice the size of the

How can I uninstall a version of a Cabal package?

蹲街弑〆低调 提交于 2019-11-28 15:20:29
Happstack Lite is breaking on me because it's getting blaze-html version 0.5 and it wants version 0.4. Cabal says that both versions 0.4.3.4 and 0.5.0.0 are installed. I want to remove the 0.5.0.0 and use just the older version. But cabal does not have an "uninstall" command, and when I try ghc-pkg unregister --force blaze-html , ghc-pkg says my command has been ignored. What do I do? UPDATE : Don't believe it . Although ghc-pkg claims to ignore the command, the command isn't ignored. And with Don Stewart's accepted answer you can remove exactly the version you wish to eliminate. Don Stewart

Good introductory text about GHC implementation?

允我心安 提交于 2019-11-28 15:03:50
When programming in Haskell (and especially when solving Project Euler problems, where suboptimal solutions tend to stress the CPU or memory needs) I'm often puzzled why the program behaves the way it is. I look at profiles, try to introduce some strictness, chose another data structure, ... but mostly it's groping in the dark, because I lack a good intuition. Also, while I know how Lisp, Prolog and imperative languages are typically implemented, I have no idea about implementing a lazy language. I'm a bit curious too. Hence I would like to know more about the whole chain from program source

Incomplete type signature

痴心易碎 提交于 2019-11-28 12:17:12
Lets say we've got a function like f below, that returns a monad. However, where you see Int , pretend it's a really complicated type. f :: (Monad m) => m Int -- Pretend this isn't Int but something complicated f = return 42 Now lets say we want to force this into the Maybe monad. We don't need to write the full type of f to do this, we can just do the following: g :: Maybe a -> Maybe a g = id main = print $ (g f) The dummy function g forces f to become Maybe . I think the above is rather messy. What I'd rather write is this: main = print $ (f :: Maybe a) But it fails with the following error:

Why is GHC complaining about non-exhaustive patterns?

£可爱£侵袭症+ 提交于 2019-11-28 10:42:35
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 matching in insert is non-exhaustive: test.hs|6| 1: || Warning: Pattern match(es) are non-exhaustive || In

Haskell Space Overflow

末鹿安然 提交于 2019-11-28 10:07:40
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 size 8388608 bytes. Use `+RTS -Ksize -RTS' to increase it. I assume this is one of the "space overflow"

Debugging infinite loops in Haskell programs with GHCi

烂漫一生 提交于 2019-11-28 09:03:13
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 values in another map depending on x' . The specifics don't matter here, but as you can probably tell, if

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

六月ゝ 毕业季﹏ 提交于 2019-11-28 08:57:30
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. Artelius 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 Monad import Char main :: IO () main = do hSetBuffering stdin NoBuffering inputLoop inputLoop :: IO

Haskell : loading ALL files in current directory path

萝らか妹 提交于 2019-11-28 08:16:03
问题 The command (in GHCi) :load abc Loads the functions in the file abc (which must exist in the current directory path). How would I load all the files in the current directory path? Thanks ---------------------------------------------------------------------------------- [RESPONSE TO POST BELOW] Hi Rotskoff, thanks I tried your suggestion but I could not get it to work, so I think I must have misunderstood something. I created 3 files test.hs, test1.hs, and test2.hs as follows : -> --test.hs