state-monad

Why does ParsecT type have 'u' argument?

你离开我真会死。 提交于 2019-11-29 10:10:02
Documentation for the parsec package states that u argument is used to carry some user state through monadic computation. But the same functionality can be achieved by basing ParsecT monad transformer on State monad. So if my parser is not stateful, i don't need u altogether, but have to set it to () with parsec. What's rationale for adding non-optional state support to ParsecT ? Because a parser of type ParsecT s () (State st) a behaves differently from a parser of type Parsec s st Identity a when it comes to backtracking: User state resets when parsec tries an alternative after a failing

How to deal with application state in Gtk2Hs

时间秒杀一切 提交于 2019-11-29 02:06:52
Trying to learn to write applications with Gtk2Hs I'm getting difficulties bridging the gap between the event driven Gtk2HS and the persistent state of my model. So to simplify, lets say that I have this simple application module Main where import Graphics.UI.Gtk import Control.Monad.State main = do initGUI window <- windowNew button <- buttonNew set button [buttonLabel := "Press me"] containerAdd window button -- Events onDestroy window mainQuit onClicked button (putStrLn ---PUT MEANINGFUL CODE HERE---) widgetShowAll window mainGUI and the state of my application is how many times the button

what is proper monad or sequence comprehension to both map and carry state across?

别说谁变了你拦得住时间么 提交于 2019-11-28 23:37:23
问题 I'm writing a programming language interpreter. I have need of the right code idiom to both evaluate a sequence of expressions to get a sequence of their values, and propagate state from one evaluator to the next to the next as the evaluations take place. I'd like a functional programming idiom for this. It's not a fold because the results come out like a map. It's not a map because of the state prop across. What I have is this code which I'm using to try to figure this out. Bear with a few

ST Monad == code smell?

淺唱寂寞╮ 提交于 2019-11-28 16:11:54
I'm working on implementing the UCT algorithm in Haskell, which requires a fair amount of data juggling. Without getting into too much detail, it's a simulation algorithm where, at each "step," a leaf node in the search tree is selected based on some statistical properties, a new child node is constructed at that leaf, and the stats corresponding to the new leaf and all of its ancestors are updated. Given all that juggling, I'm not really sharp enough to figure out how to make the whole search tree a nice immutable data structure à la Okasaki . Instead, I've been playing around with the ST

Use of Haskell state monad a code smell?

一个人想着一个人 提交于 2019-11-28 14:25:53
问题 God I hate the term "code smell", but I can't think of anything more accurate. I'm designing a high-level language & compiler to Whitespace in my spare time to learn about compiler construction, language design, and functional programming (compiler is being written in Haskell). During the code generation phase of the compiler, I have to maintain "state"-ish data as I traverse the syntax tree. For example, when compiling flow-control statements I need to generate unique names for the labels to

Difference between State, ST, IORef, and MVar

我是研究僧i 提交于 2019-11-28 13:17:19
问题 I am working through Write Yourself a Scheme in 48 Hours (I'm up to about 85hrs) and I've gotten to the part about Adding Variables and Assignments. There is a big conceptual jump in this chapter, and I wish it had been done in two steps with a good refactoring in between rather then jumping at straight to the final solution. Anyway… I've gotten lost with a number of different classes that seem to serve the same purpose: State , ST , IORef , and MVar . The first three are mentioned in the

Why does ParsecT type have 'u' argument?

為{幸葍}努か 提交于 2019-11-28 03:33:25
问题 Documentation for the parsec package states that u argument is used to carry some user state through monadic computation. But the same functionality can be achieved by basing ParsecT monad transformer on State monad. So if my parser is not stateful, i don't need u altogether, but have to set it to () with parsec. What's rationale for adding non-optional state support to ParsecT ? 回答1: Because a parser of type ParsecT s () (State st) a behaves differently from a parser of type Parsec s st

How to deal with application state in Gtk2Hs

你说的曾经没有我的故事 提交于 2019-11-27 16:24:40
问题 Trying to learn to write applications with Gtk2Hs I'm getting difficulties bridging the gap between the event driven Gtk2HS and the persistent state of my model. So to simplify, lets say that I have this simple application module Main where import Graphics.UI.Gtk import Control.Monad.State main = do initGUI window <- windowNew button <- buttonNew set button [buttonLabel := "Press me"] containerAdd window button -- Events onDestroy window mainQuit onClicked button (putStrLn ---PUT MEANINGFUL

Scalaz state monad examples

♀尐吖头ヾ 提交于 2019-11-27 10:13:26
I haven't seen many examples of the scalaz state monad. There is this example but it is hard to understand and there is only one other question on stack overflow it seems. I'm going to post a few examples I've played with but I would welcome additional ones. Also if somebody can provide example on why init , modify , put and gets are used for that would be great. Edit: here is an awesome 2 hours presentation on the state monad. I assume, scalaz 7.0.x and the following imports (look at answer history for scalaz 6.x ): import scalaz._ import Scalaz._ The state type is defined as State[S, A]

Scalaz state monad examples

a 夏天 提交于 2019-11-26 15:04:33
问题 I haven't seen many examples of the scalaz state monad. There is this example but it is hard to understand and there is only one other question on stack overflow it seems. I'm going to post a few examples I've played with but I would welcome additional ones. Also if somebody can provide example on why init , modify , put and gets are used for that would be great. Edit: here is an awesome 2 hours presentation on the state monad. 回答1: I assume, scalaz 7.0.x and the following imports (look at