haskell

What's a space leak?

我怕爱的太早我们不能终老 提交于 2019-12-30 02:09:26
问题 I found the haskell wiki page on space leaks, which claims to list examples of real-world leaks, which it doesn't. It doesn't really say what a space leak is; it just links to the page for memory leaks. What's a space leak? 回答1: As noted in @Rasko's answer, a space leak refers to a situation where a program or specific computation uses more (usually much more) memory than is necessary for the computation and/or expected by the programmer. Haskell programs tend to be particularly susceptible

How to specify dependency on external C library in .cabal?

蓝咒 提交于 2019-12-30 02:03:26
问题 I maintain a library with FFI bindings on Hackage. So my Haskell library depends on the corresponding C library and its header files. Now I specify the external dependency in the .cabal file like this: PkgConfig-Depends: libfoo >= 1.2 And it works well for me in Linux. However, I have a user of the library who reports, that installing pkg-config on Windows is rather cumbersome, and instead he prefers Includes: foo.h Extra-libraries: foo I'd like my library to be as easy to build as possible,

How to specify dependency on external C library in .cabal?

风流意气都作罢 提交于 2019-12-30 02:03:25
问题 I maintain a library with FFI bindings on Hackage. So my Haskell library depends on the corresponding C library and its header files. Now I specify the external dependency in the .cabal file like this: PkgConfig-Depends: libfoo >= 1.2 And it works well for me in Linux. However, I have a user of the library who reports, that installing pkg-config on Windows is rather cumbersome, and instead he prefers Includes: foo.h Extra-libraries: foo I'd like my library to be as easy to build as possible,

Is it possible to implement MonadFix for `Free`?

爱⌒轻易说出口 提交于 2019-12-30 01:41:05
问题 http://hackage.haskell.org/package/free in Control.Monad.Free.Free allows one to get access to the "free monad" for any given Functor . It does not, however, have a MonadFix instance. Is this because such an instance cannot be written, or was it just left out? If such an instance cannot be written, why not? 回答1: Consider the description of what mfix does: The fixed point of a monadic computation. mfix f executes the action f only once, with the eventual output fed back as the input. The word

Allowing cross-origin requests in Yesod

本秂侑毒 提交于 2019-12-30 00:56:08
问题 My application uses a bookmarklet, and I need to allow CORS for MyRouteR so my bookmarklet code can use this route for AJAX requests. In my first draft of config/routes I gave MyRouteR support for only one request method, PUT. But it turned out (duh) that I'd need to support the OPTIONS method as well, which browsers use for CORS preflight requests. I ended up with the following in config/routes: /myroute MyRouteR PUT OPTIONS I was kind of hoping there would be some relevant machinery in the

Subtraction of church numerals in haskell

不羁岁月 提交于 2019-12-30 00:52:11
问题 I'm attempting to implement church numerals in Haskell, but I've hit a minor problem. Haskell complains of an infinite type with Occurs check: cannot construct the infinite type: t = (t -> t1) -> (t1 -> t2) -> t2 when I try and do subtraction. I'm 99% positive that my lambda calculus is valid (although if it isn't, please tell me). What I want to know, is whether there is anything I can do to make haskell work with my functions. module Church where type (Church a) = ((a -> a) -> (a -> a))

Haskell Bytestrings: How to pattern match?

怎甘沉沦 提交于 2019-12-30 00:33:06
问题 I'm a Haskell newbie, and having a bit of trouble figuring out how to pattern match a ByteString . The [Char] version of my function looks like: dropAB :: String -> String dropAB [] = [] dropAB (x:[]) = x:[] dropAB (x:y:xs) = if x=='a' && y=='b' then dropAB xs else x:(dropAB $ y:xs) As expected, this filters out all occurrences of "ab" from a string. However, I have problems trying to apply this to a ByteString . The naive version dropR :: BS.ByteString -> BS.ByteString dropR [] = [] dropR (x

Haskell Bytestrings: How to pattern match?

荒凉一梦 提交于 2019-12-30 00:33:03
问题 I'm a Haskell newbie, and having a bit of trouble figuring out how to pattern match a ByteString . The [Char] version of my function looks like: dropAB :: String -> String dropAB [] = [] dropAB (x:[]) = x:[] dropAB (x:y:xs) = if x=='a' && y=='b' then dropAB xs else x:(dropAB $ y:xs) As expected, this filters out all occurrences of "ab" from a string. However, I have problems trying to apply this to a ByteString . The naive version dropR :: BS.ByteString -> BS.ByteString dropR [] = [] dropR (x

What's the relationship between profunctors and arrows?

戏子无情 提交于 2019-12-29 19:58:50
问题 Apparently, every Arrow is a Strong profunctor. Indeed ^>> and >>^ correspond to lmap and rmap . And first' and second' are just the same as first and second . Similarly every ArrowChoice is also Choice. What profunctors lack compared to arrows is the ability to compose them. If we add composition, will we get an arrow? In other words, if a (strong) profunctor is also a category, is it already an arrow? If not, what's missing? 回答1: What profunctors lack compared to arrows is the ability to

Functional languages (Erlang, F#, Haskell, Scala)

最后都变了- 提交于 2019-12-29 18:50:10
问题 1) Are functional languages suited for web applications development? 2) Are functional languages suited for business/ERP/CRM type of applications? 回答1: Functional languages of the kind you describe are general purpose programming languages, they're used for all manner of things, including web apps and business apps. (I use Haskell). Is Haskell good for Web Apps? Building commerical web apps in Haskell As gabor implies, ultimately it comes down to libraries. Scala has a web framework: lift.