Applicative provides "operator" <*>, which I can use as follows: val f: (Int, Int) => Int = {(x, y) => x + y} 1.some <*> (2.some <*> f.curried.some) In addition to that scalaz provides ApplicativeBuilder: (1.some |@| 2.so
I'm trying to chain together functions via the applicative functor pattern, but I'm having a problem compiling my code: import Control.Applicative buildMyList :: Float -> Float -> [Float] buildMyList ul tick = [p | p <- [0,tick..ul]] myFunct
This is a follow-up to my previous question. As I understand from Haxl and Stitch they use a monad for data access. The monad is actually a tree of data access commands. The children are the commands the node depends on. The siblings are executed con
I've run in to a few situations where I need the list: [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)] -- no (0,0) Note that there is no (0,0) in the list. I use the (dx,dy) tuples to search up, down, left, right and diagonally from a coordin
Have all the Haskell instances of Applicative typeclass that we get with the Haskell platform been proved to satisfy all the Applicative laws? If yes, where do we find those proofs? The source code of Control.Applicative does not seem to contain any
From Josh Suereth's "Scala in Depth": "Applicative functors provide a way to take two computations and join them together using a function. The Traversable example highlights how two collections can be parallelized into pairs. Applicative functors an
I've been reading about applicative functors, notably in the Functional Pearl by McBride and Paterson. But I'd like to solidify my understanding by doing some exercises. I'd prefer programming exercises but proof exercises are OK too. What exercises
The standard-library Haskell typeclasses MonadPlus, Alternative, and Monoid each provide two methods with essentially the same semantics: An empty value: mzero, empty, or mempty. An operator a -> a -> a that joins values in the typeclass togeth
I'm trying to write a function like mapFst :: Maybe (a, String) -> Maybe ([a], String) mapFst (a,s) = (:) <$> (a,s) <*> [other fun with same type as mapFst] (a,s) Here, I'm trying to build a list based on the first element of a tuple,
I'm helping a friend learn Haskell and he recently created code like this, which type checks and produces a CPU-burning loop at runtime. I'm completely baffled by this. import Control.Monad import Control.Applicative main = forever putStrLn "Hello, i
While learning Scalaz 6, I'm trying to write type-safe readers returning validations. Here are my new types: type ValidReader[S,X] = (S) => Validation[NonEmptyList[String],X] type MapReader[X] = ValidReader[Map[String,String],X] and I have two fun
Assume we have two lists : val l1=List("a","b","c") val l2 = List("1","2","3") What I want is : List("a1", "b2", "c3") that is, adding the nth element of l1 with the nth element of l2 A way to achieve it is : (l1 zip l2).map (c => {c._1+c._2}) I j
Monads are known to be theoretically a subset of functors and specifically applicative functors, even though it's not indicated in Haskell's type system. Knowing that, given a monad and basing on return and bind, how to: derive fmap, derive <*>
I'm trying to do what must be blindingly obvious in Haskell, which is go from Just [1] and Just [2] to Just [1, 2]. However I can't find anything online as I keep finding related but unhelpful pages. So, how do you achieve this? --------------Solutio
I think I kind of understand how applicative functors work in Haskell and I'm using them for basic datatypes (Maybe, Either...). However, I found this question with the following example: withPool pool = bracket (takeConn pool) (putConn pool) can be
I am a beginner with haskell and am reading the Learn you a haskell book. I have been trying to digest functors and applicative functors for a while now. In the applicative functors topic, the instance implementation for Maybe is given as instance Ap
Looking at the docs for Control.Applicative, I notice that they have instance declarations for certain monads (e.g. IO, Maybe and notably ST), but there are no instances for MTL monads such as State and RWS. Instead it looks like there's a general-pu
In ghci: λ> :t (pure 1) (pure 1) :: (Applicative f, Num a) => f a λ> show (pure 1) <interactive>:1:1: No instance for (Show (f0 a0)) arising from a use of `show' Possible fix: add an instance declaration for (Show (f0 a0)) In the expre
After having read Anthony's response on a style-related parser question, I was trying to convince myself that writing monadic parsers can still be rather compact. So instead of reference :: Parser Transc reference = try $ do string "#{" a <- numbe
There seems to be a consensus that you should use Parsec as an applicative rather than a monad. What are the benefits of applicative parsing over monadic parsing? style performance abstraction Is monadic parsing out? --------------Solutions----------