haskell

Why is `stack build` altering my .cabal file?

ぐ巨炮叔叔 提交于 2019-12-31 02:20:25
问题 I am attempting to build a project which uses Euterpea. Running stack build I get the following error, suggesting that I need to add Euterpea to the build-depends section of my .cabal file. $ sb composition-0.1.0.0: build (lib + exe) Preprocessing library composition-0.1.0.0... [2 of 2] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0/build/Lib.o ) /home/matthew/backup/composition/composition/src/Lib.hs:5:1: error: Failed to load interface for ‘Euterpea’ It is a

Why is `stack build` altering my .cabal file?

风流意气都作罢 提交于 2019-12-31 02:19:06
问题 I am attempting to build a project which uses Euterpea. Running stack build I get the following error, suggesting that I need to add Euterpea to the build-depends section of my .cabal file. $ sb composition-0.1.0.0: build (lib + exe) Preprocessing library composition-0.1.0.0... [2 of 2] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0/build/Lib.o ) /home/matthew/backup/composition/composition/src/Lib.hs:5:1: error: Failed to load interface for ‘Euterpea’ It is a

Preventing caching of computation in Criterion benchmark

核能气质少年 提交于 2019-12-31 01:46:26
问题 The following code (suggested by Reid Barton at Criterion causing memory consumption to explode, no CAFs in sight) has a benchmark time which scales proportionally with num when compiled with O0 optimization. However using O3 optimization seems to result in a benchmark time which is independent of num . Where in the core is the result being cached, and what can I do to prevent it from being cached? The code is : {-# OPTIONS_GHC -fno-cse #-} {-# LANGUAGE BangPatterns #-} module Main where

Monads, composition and the order of computation

喜欢而已 提交于 2019-12-31 01:25:33
问题 All the monad articles often state, that monads allow you to sequence effects in order. But what about simple composition? Ain't f x = x + 1 g x = x * 2 result = f g x requires g x to be computed before f ... ? Do monads do the same but with handling of effects? 回答1: Disclaimer : Monads are a lot of things. They are notoriously difficult to explain, so I will not attempt to explain what monads are in general here, since the question does not ask for that. I will assume you have a basic grasp

Haskell/GHC performance of `any`/`all`

妖精的绣舞 提交于 2019-12-31 00:56:45
问题 I wrote quantification functions exists , forall , and none for Haskell's build-in [] list data type. On multiple occasions, these seemed to prove much more efficient than Prelude / Data.List s any and all . I naively suspect that this performance is due to any and all being implemented using Θ(n) folds. Since I am relatively new to Haskell, I think I must be mistaken, or that there would be a good reason for this phenomenon. From Data.Foldable : -- | Determines whether any element of the

Why does windows need withSocketsDo?

和自甴很熟 提交于 2019-12-30 23:32:34
问题 In windows, sockets need to be initialized, as shown in Networks. On Windows operating systems, the networking subsystem has to be initialised using withSocketsDo before any networking operations can be used. eg. main = withSocketsDo $ do {...} Although this is only strictly necessary on Windows platforms, it is harmless on other platforms, so for portability it is good practice to use it all the time. What's special about windows? 回答1: In existing versions of the network library,

Greaters function define

情到浓时终转凉″ 提交于 2019-12-30 23:21:48
问题 I would like to define a greaters function, which selects from a list items that are larger than the one before it. For instance: greaters [1,3,2,4,3,4,5] == [3,4,4,5] greaters [5,10,6,11,7,12] == [10,11,12] The definition I came up with is this : greaters :: Ord a => [a] -> [a] Things I tried so far: greaters (x:xs) = group [ d | d <- xs, x < xs ] Any tips? 回答1: I would start from here: greaters :: Ord a => [a] -> [a] greaters [] = [] greaters (x:xs) = greatersImpl x xs where greatersImpl

How to override Show instance of some basic types in Haskell?

僤鯓⒐⒋嵵緔 提交于 2019-12-30 20:40:46
问题 I'm writting some programs in Haskell, dealing with a lot of basic types like Word32/Word64 etc.. I use ghci to test the functions frequently, see the results in terminal. To be convenient and fast, I always show data in hexadecimal e.g. data Human = M Int | F Int instance Show Human where show M x = printf "man, age %d" x show F x = printf "woman, age %d" x but I want basic types to be showed in hexadecimal (espacially in ghci). I found instance declaration cannot be overridden. and I don't

Slightly generalizing unfold

為{幸葍}努か 提交于 2019-12-30 20:34:24
问题 Data.List defines unfoldr :: (b -> Maybe (a, b)) -> b -> [a] unfoldr f b = case f b of Just (a,new_b) -> a : unfoldr f new_b Nothing -> [] There are a number of functions that can almost be defined using unfoldr , but have trouble at the very end of the list. A simple "fix" is unfoldr' :: (b -> Either (a,b) [a]) -> b -> [a] unfoldr' f b = case f b of Left (a, new_b) -> a : unfoldr' f new_b Right r -> r Does this function have a standard name? Does it have nice properties and interact well

Convert a “do” notation with more than two actions to use the bind function

主宰稳场 提交于 2019-12-30 18:42:07
问题 I know that the following "do" notation's "bind" function is equivalent to getLine >>= \line -> putStrLn do line <- getLine putStrLn line But how is the following notation equivalent to bind function? do line1 <- getLine putStrLn "enter second line" line2 <- getLine return (line1,line2) 回答1: I take it you are trying to see how to bind the result of "putStrLn". The answer is in the type of putStrLn: putStrLn :: String -> IO () Remember that "()" is the unit type, which has a single value (also