haskell

How to modify cabal config file on windows

假如想象 提交于 2019-12-30 06:52:51
问题 I am installing Haskell on my desktop, which is windows system. I follow the instruction. It says: Modify your cabal config file (you can verify the location by running "cabal user-config init") to contain the following lines: extra-prog-path: C:\Program Files\Haskell Platform\8.0.2\msys\usr\bin extra-lib-dirs: C:\Program Files\Haskell Platform\8.0.2\mingw\lib extra-include-dirs: C:\Program Files\Haskell Platform\8.0.2\mingw\include I tried to call "cabal user-config init" in command prompt,

Implying equality in a Haskell pattern match

流过昼夜 提交于 2019-12-30 06:10:50
问题 I'm writing a function to simplify a Boolean expression. For example, Nand(A, A) == Not(A) . I've tried to implement this particular rule using pattern matching, like so: -- Operands equivalent - simplify! simplify (Nand q q) = Not (simplify q) -- Operands must be different, so recurse. simplify (Nand q q') = Nand (simplify q) (simplify q') Upon compiling, I get the error: Conflicting definitions for `q' Bound at: boolean.hs:73:21 boolean:73:29 In an equation for `simplify' I think I

Test if all elements of a Foldable are the same

无人久伴 提交于 2019-12-30 06:04:07
问题 I built a function that verifies that all elements of a foldable structure are equal. Compared to a similar function on the lists, it seems to me that the more general function is disproportionately complex, but I have not been able to simplify it. Do you have any suggestions? import Data.Monoid import Data.Sequence as SQ import Data.Matrix as MT allElementsEqualL :: Eq a => [a] -> Bool allElementsEqualL [] = True allElementsEqualL (x:ns) = all (== x) ns -- allElementsEqualL [1,1,1] -> True

Any nice tools for untying knots in Haskell?

坚强是说给别人听的谎言 提交于 2019-12-30 06:00:41
问题 I've a data structure with several different types of internal circular linking, making it infinite in the sense of say the cycle command. Are there any interesting modules for collapsing such structures into flat data structures that use indexing instead? I'm interested in serializing the complete data structure, both via Read and Show as well as via Data.Serialize or similar. There are obviously nice features of building a sequential index, but an index based upon hash values of memory

How to modify using a monadic function with lenses?

喜你入骨 提交于 2019-12-30 05:57:06
问题 I needed a lens function that works like over , but with monadic operations: overM :: (Monad m) => Lens s t a b -> (a -> m b) -> (s -> m t) While this function is easy to define (it's actually just an identity modulo WrappedMonad ), I wonder are such functions defined somewhere in lens ? {-# LANGUAGE RankNTypes #-} import Control.Applicative import Control.Lens overF :: (Functor f) => Lens s t a b -> (a -> f b) -> (s -> f t) overF l = l overM :: (Monad m) => Lens s t a b -> (a -> m b) -> (s -

Alternative implementations of Haskell's standard library type classes

北城以北 提交于 2019-12-30 05:48:06
问题 I've seen many people complaining about some of the type classes from the standard library saying things like "Monad should require Functor" or even "Monad should require Applicative", "Applicative should require Pointed", "Num shouldn't require Show", etc, So, I have some questions: Are there arguments for the way the tree of type class dependencies have those "flaws" perceived by the community or is this just the result of how things were done historically? How drastically a change in this

Accumulating errors with EitherT

穿精又带淫゛_ 提交于 2019-12-30 04:50:10
问题 I have the following little mini-sample application of a web API that takes a huge JSON document and is supposed to parse it in pieces and report error messages for each of the pieces. Following code is a working example of that using EitherT (and the errors package). However, the problem is that EitherT breaks the computation on the first Left encountered and just returns the first "error" it sees. What I would like is a list of error messages, all that are possible to produce. For instance,

What's the ideal implementation for the Sieve of Eratosthenes between Lists, Arrays, and Mutable Arrays?

社会主义新天地 提交于 2019-12-30 04:45:18
问题 In Haskell, I've found three simple implementations of the Sieve of Eratosthenes on the Rosetta Code page. Now my question is, which one should be used in which situations? Correcting my initial reasoning would be helpful too: I'm assuming the List one is the most idiomatic and easy to read for a Haskeller. Is it correct, though? I'm wondering if it suffers from the same problems as another list-based sieve that I then learned was not actually implementing the algorithm: (edit: shown here is

How do I test for an error in Haskell?

白昼怎懂夜的黑 提交于 2019-12-30 04:37:05
问题 I want to be able to make sure a function will throw an error when it receives and invalid value. For example, let says I have a function pos that only returns a positive number: pos :: Int -> Int pos x | x >= 0 = x | otherwise = error "Invalid Input" This is a simplistic example, but I hope you get the idea. I want to be able to write a test case that will expect an error and consider it a passing test. For example: tests = [pos 1 == 1, assertError pos (-1), pos 2 == 2, assertError pos (-2)]

Redirections in Servant

不羁岁月 提交于 2019-12-30 04:23:06
问题 What's the appropriate way to make a Servant handler respond with a redirection? I am working in a navigation REST app and I would like to respond to POST requests that create resources with a redirection to the corresponding GET resource list paths. So for instance POST /foos should redirect to GET /foos after creating a foo. I could not find a clear way to do that in the documentation. 回答1: There is one simple (but slightly hacky) answer, and a lead for making the first option obsolete