haskell

regex-pcre on Windows

随声附和 提交于 2020-06-10 05:57:00
问题 How can I install regex-pcre on Windows? cabal install regex-pcre Resolving dependencies... Configuring regex-pcre-0.94.4... cabal: Missing dependency on a foreign library: * Missing C library: pcre This problem can usually be solved by installing the system package that provides this library (you may need the "-dev" version). If the library is already installed but in a non-standard location then you can use the flags --extra-include-dirs= and --extra-lib-dirs= to specify where it is. Failed

regex-pcre on Windows

為{幸葍}努か 提交于 2020-06-10 05:56:48
问题 How can I install regex-pcre on Windows? cabal install regex-pcre Resolving dependencies... Configuring regex-pcre-0.94.4... cabal: Missing dependency on a foreign library: * Missing C library: pcre This problem can usually be solved by installing the system package that provides this library (you may need the "-dev" version). If the library is already installed but in a non-standard location then you can use the flags --extra-include-dirs= and --extra-lib-dirs= to specify where it is. Failed

Why does function concat use foldr? Why not foldl'

只谈情不闲聊 提交于 2020-06-10 04:27:08
问题 In most resources it is recommended to use foldl', but that cause of using foldr in concat instead of foldl'? 回答1: EDIT I talk about laziness and productivity in this answer, and in my excitement I forgot a very important point that jpmariner focuses on in their answer: left-associating (++) is quadratic time! foldl' is appropriate when your accumulator is a strict type, like most small types such as Int , or even large spine-strict data structures like Data.Map . If the accumulator is strict

Why does function concat use foldr? Why not foldl'

[亡魂溺海] 提交于 2020-06-10 04:27:00
问题 In most resources it is recommended to use foldl', but that cause of using foldr in concat instead of foldl'? 回答1: EDIT I talk about laziness and productivity in this answer, and in my excitement I forgot a very important point that jpmariner focuses on in their answer: left-associating (++) is quadratic time! foldl' is appropriate when your accumulator is a strict type, like most small types such as Int , or even large spine-strict data structures like Data.Map . If the accumulator is strict

case on monadic value

最后都变了- 提交于 2020-06-09 11:04:26
问题 Is there a way to perform a case on the value stored within a monad without having to bind a name to it? i.e. instead of doing this: c <- getChar case c of ... Is there a way to do this: mcase getChar of ... Alternatively, it would be nice if the case statement could be partially applied so: case of ... would be desugared to: \a -> case a of ... So you could do this: getChar >>= case of ... 回答1: The answer is no. In Haskell 98, you can't use a case statement without using a name inside it.

What is the difference between Fix, Mu and Nu in Ed Kmett's recursion scheme package

做~自己de王妃 提交于 2020-06-09 09:25:54
问题 In Ed Kmett's recursion-scheme package, there are three declarations: newtype Fix f = Fix (f (Fix f)) newtype Mu f = Mu (forall a. (f a -> a) -> a) data Nu f where Nu :: (a -> f a) -> a -> Nu f What is the difference between those three data types? 回答1: Mu represents a recursive type as its fold, and Nu represents it as its unfold. In Haskell, these are isomorphic, and are different ways to represent the same type. If you pretend that Haskell doesn't have arbitrary recursion, the distinction

Is there a pretty/glib way to restrict a curry-ed function to the graph of another function in Haskell?

眉间皱痕 提交于 2020-05-31 04:55:34
问题 I finally got bored enough in quarantine to start learning Haskell today and I'm really enjoying myself, I really love the aesthetics of the language. Hopefully this question doesn't inspire any hate if it has already been posted here before, etc. It's very simple, but I'm an absolute beginner. I've been trying to understand how to do some simple things elegantly (or at least in a so-called "point free" way) with the language and came upon the problem of how to describe in a clean way the

Two polymorphic classes in one function

99封情书 提交于 2020-05-29 07:03:31
问题 I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $ ClientData "" return result addServer :: String -> State ClientData () addServer _ = return () scenario1 :: State ModelData () scenario1 = do act "Alice" $ addServer "https://example.com" I am trying to generalise it with polymorphic type-classes

Two polymorphic classes in one function

走远了吗. 提交于 2020-05-29 07:03:17
问题 I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $ ClientData "" return result addServer :: String -> State ClientData () addServer _ = return () scenario1 :: State ModelData () scenario1 = do act "Alice" $ addServer "https://example.com" I am trying to generalise it with polymorphic type-classes

Two polymorphic classes in one function

谁说我不能喝 提交于 2020-05-29 07:02:13
问题 I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $ ClientData "" return result addServer :: String -> State ClientData () addServer _ = return () scenario1 :: State ModelData () scenario1 = do act "Alice" $ addServer "https://example.com" I am trying to generalise it with polymorphic type-classes