Questions tagged [writer-monad]

27 questions
1
vote
2 answers

Question about the Writer monad as taught in LYAH. (How did the appending to the log take place?)

I'm learning Haskell from the "Learn you a Haskell for Great Good" tutorial and I've got to the part on writer monads. Here's the example that I can't figure out. import Control.Monad.Writer logNumber :: Int -> Writer [String] Int logNumber x =…
Andy
  • 11
  • 2
1
vote
2 answers

Stacking monads Writer and OptionT

I have the following code: override def getStandsByUser(email: String): Try[Seq[Stand]] = (for { user <- OptionT(userService.findOneByEmail(email)): Try[Option[User]] stands <- OptionT.liftF(standService.list()):[Try[List[Stand]]] …
Sergii Shevchyk
  • 38,716
  • 12
  • 50
  • 61
1
vote
1 answer

Haskell Write Monad for expressions

I am trying to design embedded language, where operations can raise certain flags depending on values. I foresee operation on scalar values as well as on vectors (e.g. map, fold, etc.) My idea is to use Writer Monad to keep track of flags.…
krokodil
  • 1,326
  • 10
  • 18
1
vote
1 answer

Validating XML with Writer and Kleisli in Scala

This is a follow-up to my previous question Suppose I need to validate an XML like this: xxxyyyzzz I need to make sure that the root element has label a and also has children xxx, yyy,…
Michael
  • 41,026
  • 70
  • 193
  • 341
0
votes
1 answer

The Writer monad and its type declaration

I am trying to get a better understanding of Monads and I am currently looking into the Write Monad in http://learnyouahaskell.com/for-a-few-monads-more#writer I don't understand its type declaration that seemingly consists of two types, nor do I…
0
votes
3 answers

How to lift a value into a monad

I'm trying to use the Writer monad in OCaml. module Writer : Monad = struct type 'a t = 'a * string let return x = (x, "") let (>>=) m f = let (x, s1) = m in let (y, s2) = f x in (y, s1 ^ s2) end The statement below…
0
votes
1 answer

How define instance Monad Writer with custom data type

I have module: module Writer where import Prelude hiding (Monad, (>>=), return, (=<<)) main = putStrLn "hello" class Monad m where return :: a -> m a (>>=) :: m a -> (a -> m b) -> m b (=<<) :: (a -> m b) -> m a -> m b (=<<) = flip…
Boris Azanov
  • 4,408
  • 1
  • 15
  • 28
0
votes
1 answer

Writer monad and unsequence

I am using the Writer monad to keep track of an error ("collision") flag on arbitrary values (such as Int). Once the flag is set it is "sticky" and attaches itself to all values produced as a result of any operation with the marked one. Sometimes…
krokodil
  • 1,326
  • 10
  • 18
0
votes
2 answers

Function composition with the Writer monad?

I'm studying the Writer monad and have the following: myFunction :: Int -> Int -> Writer String Int myFunction e1 e2 | e1 > e2 = do tell ("E1 greater") return (e1) | otherwise = do tell ("E2 greater") return…
Babra Cunningham
  • 2,949
  • 1
  • 23
  • 50
0
votes
2 answers

How do I access both the value and accumulator of a Writer monad within a 'do' block (PureScript)?

I'm learning about the Writer monad right now, and I'm not sure if it's correct to want to read both the value and the accumulator of the monad within a do block. For example, in the coltzSeq function below I want to read the length of the Array…
Albtzrly
  • 924
  • 1
  • 6
  • 15
0
votes
1 answer

context bound of scalar.Coyoneda.liftTF

Finished watching thought-provoking video "Composable application architecture with reasonably priced monads" from Rúnar Bjarnason, I started to write the examples provided in the video in Scalaz. I am having a little surprise when implementing the…
Sheng
  • 1,697
  • 4
  • 19
  • 33
0
votes
2 answers

Where is the official definition of 'bind' and 'return' for the Writer Monad in Haskell?

So far I have found: http://monads.haskell.cz/html/writermonad.html http://en.wikipedia.org/wiki/Monad_(functional_programming) which give definitions for >>= and return Where is the official code?
haroldcarr
  • 1,523
  • 15
  • 17
1
2