ghc

Iteratively printing every integer in a List

人走茶凉 提交于 2020-01-15 04:28:07
问题 Say I have a List of integers l = [1,2] Which I want to print to stdout . Doing print l produces [1,2] Say I want to print the list without the braces map print l produces No instance for (Show (IO ())) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO ())) In a stmt of an interactive GHCi command: print it `:t print print :: Show a => a -> IO () So while I thought this would work I went ahead and tried: map putStr $ map show l Since I suspected a type

Implicit parameter and function

谁说胖子不能爱 提交于 2020-01-14 07:27:47
问题 I have a problem considering implicit parameters in Haskell (GHC). I have a function f , that assumes the implicit parameter x , and would like to encapsulate it in a context by applying f to g f :: (?x :: Int) => Int -> Int f n = n + ?x g :: (Int -> Int) -> (Int -> Int) g t = let ?x = 5 in t But when i try to evaluate g f 10 I get an error that x is not bound, e.g.: Unbound implicit parameter (?x::Int) arising from a use of `f' In the first argument of `g', namely `f' In the second argument

How to use the epoll/kqueue enabled version of GHC/Haskell for network connections?

坚强是说给别人听的谎言 提交于 2020-01-14 04:24:08
问题 There is a lot of old information on the net regarding an epoll/kqueue enabled GHC. For example, the code on the Simple Servers wiki page doesn't compile anymore. Could someone provide a basic example of how to use this feature with a modern GHC version to build, e.g. a TCP server that just responds with "Hello" on connect? 回答1: GHC's IO manager uses epoll/kqueue under the hood without any special programmer effort. Just write the naive threaded program -- that puts each concurrent blocking

A change in my library made it much slower. Profiling isn't helping me. What might be the reason for the slow-down?

怎甘沉沦 提交于 2020-01-13 08:28:08
问题 My Problem, Briefly I made a change to my library, now it's much slower but I can't figure out where it spends all that additional time. Profiling reports are not helping. Please help me figure out what the reason might be. Some Context I made a Redis client-library called Hedis and have a benchmark program for it. Now, I made some internal changes to the library, to clean up the architecture. This caused performance (in Redis-requests per second, as measured by said benchmark) to drop by a

Control.Parallel compile issue in Haskell

若如初见. 提交于 2020-01-13 07:55:09
问题 The compiler is complaining each time on different example applications of parallel Haskell; with this message: Could not find module `Control.Parallel.Strategies' The ghc compiler command: ghc -threaded -i/sudo/dir/par-modules/3 -cpp -DEVAL_STRATEGIES -eventlog --make parFib.hs Same with simpler ghc -O2 --make -threaded parFib.hs What detail am I overlooking? Am I missing some PATH variable. Imports can look like this: module Main where import System # if defined(EVAL_STRATEGIES) import

Can I disable the “non-exhaustive pattern matches” warning only for lambdas?

ぃ、小莉子 提交于 2020-01-12 07:04:00
问题 Can I disable the non-exhaustive pattern matches warning only for lambdas? I like the warning in general, but not for actual lambda literals like this: map (\(x:xs)->...) ls I think this code makes it pretty clear that I expect all the values of ls to always have at least one element, and there is no neat way to handle the error case in the lambda. (I guess I could move the pattern match into a case statement, but that would just be ugly.) 回答1: Yes, but only in GHC 7.2 onwards; pass -fno-warn

Can I disable the “non-exhaustive pattern matches” warning only for lambdas?

て烟熏妆下的殇ゞ 提交于 2020-01-12 07:03:28
问题 Can I disable the non-exhaustive pattern matches warning only for lambdas? I like the warning in general, but not for actual lambda literals like this: map (\(x:xs)->...) ls I think this code makes it pretty clear that I expect all the values of ls to always have at least one element, and there is no neat way to handle the error case in the lambda. (I guess I could move the pattern match into a case statement, but that would just be ugly.) 回答1: Yes, but only in GHC 7.2 onwards; pass -fno-warn

Always guaranteed evaluation order of `seq` (with strange behavior of `pseq` in addition)

余生颓废 提交于 2020-01-12 06:30:23
问题 The documentation of seq function says the following: A note on evaluation order: the expression seq a b does not guarantee that a will be evaluated before b . The only guarantee given by seq is that the both a and b will be evaluated before seq returns a value. In particular, this means that b may be evaluated before a . If you need to guarantee a specific order of evaluation, you must use the function pseq from the "parallel" package. So I have a lazy version of sum function with

When is unsafeInterleaveIO unsafe?

我是研究僧i 提交于 2020-01-11 15:28:33
问题 Unlike other unsafe* operations, the documentation for unsafeInterleaveIO is not very clear about its possible pitfalls. So exactly when is it unsafe? I would like to know the condition for both parallel/concurrent and the single threaded usage. More specifically, are the two functions in the following code semantically equivalent? If not, when and how? joinIO :: IO a -> (a -> IO b) -> IO b joinIO a f = do !x <- a !x' <- f x return x' joinIO':: IO a -> (a -> IO b) -> IO b joinIO' a f = do !x

How to detect if a program has been compiled using -threaded?

寵の児 提交于 2020-01-11 04:32:05
问题 I'm working on a Haskell daemon that uses POSIX fork/exec together with file locking mechanism. My experiments show that file locks aren't inherited during executeFile with -threaded runtime (see also this thread), no matter if I use +RTS -N or not. So I'd like to add a check to be sure that the daemon ins't compiled with -threaded . Is there a portable way to detect it? 回答1: There is a value in Control.Concurrent for this, for example: module Main (main) where import Control.Concurrent main