state-monad Questions
1
Solved
Take the MaybeT monad transformer:
newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }
I wouldn't have expected a different definition for it, because Maybe is just kind of a box with a (opti...
Nissensohn asked 11/4 at 20:25
3
Solved
I'm reading PureScript by Example and got to the part introducing the Reader monad. The example goes like this:
createUser :: Reader Permissions (Maybe User)
createUser = do
permissions <- ask...
Drugstore asked 13/10, 2017 at 21:20
1
I am working on understanding the State monad and have written two simple versions of the famous fibonacci to memoize the function. The one with let in the body runs very slowly. The one with <-...
Heartless asked 12/10, 2021 at 22:7
1
Solved
In Haskell, here's a monad that combines the State and Maybe monads:
type StatefulMaybe a = StateT Int Maybe a
This is a computation that can succeed (returning a value) or fail. If it succeeds, i...
Revenge asked 7/4, 2021 at 19:26
1
Solved
I am fairly new to Haskell. I am trying to combine the State monad with error propagation by treating Either as a monad. I would like to recurse over an abstract syntax tree (for example, for writi...
Larcher asked 10/3, 2020 at 17:19
2
Solved
I am trying to define a family of state machines with somewhat different kinds of states. In particular, the more "complex" state machines have states which are formed by combining the states of si...
Wira asked 4/12, 2019 at 17:27
2
Solved
I'm using the State monad from the Scala Cats library to compose imperative sequences of state transitions in a functional manner.
My actual use-case is quite complicated, so to simplify matters, ...
Bendwise asked 29/7, 2019 at 16:16
1
Solved
When I design my programming model I always have a dilemma which approach is better:
type MyMonad1 = StateT MyState (Reader Env)
type MyMonad2 = ReaderT Env (State MyState)
What are the benefits a...
Collado asked 2/6, 2019 at 13:14
3
Solved
I'm trying so hard to wrap my head around the State Monad, and I do not understand the following:
Given the implementation of return and (>>=), when you say State $ \s ->...., where does ...
Amabelle asked 20/5, 2019 at 13:17
6
I need to write a state monad that can also support error handling. I was thinking of using the Either monad for this purpose because it can also provide details about what caused the error. I foun...
Leede asked 31/10, 2010 at 14:58
1
Solved
Reverse State monad is really nice and mind blowing example of Haskell language's expressiveness and lazy evaluation. But it's not that easy to understand this monad. Moreover, it's really hard to ...
Jude asked 30/4, 2017 at 23:36
1
Solved
zoom allows us to use a state action that only uses some state variables, in a context where more variables are actually defined.
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Cont...
Passer asked 16/8, 2018 at 11:33
2
Solved
Using the StateT monad transformer, I can create the type StateT s [] a, which is isomorphic to s -> [(a, s)]. Now I would prefer to use the STT monad transformer instead, as I would like to hav...
Nimitz asked 16/8, 2018 at 9:59
3
Solved
To generate x86 assembly code, I have defined a custom type called X86:
data X86 a = X86 { code :: String, counter :: Integer, value :: (X86 a -> a) }
This type is used in do-notation like th...
Ephemerid asked 27/3, 2018 at 2:4
2
Solved
I'm intrigued by the construction described here for determining a monad transformer from adjoint functors. Here's some code that summarizes the basic idea:
{-# LANGUAGE MultiParamTypeClasses #-}
...
Letendre asked 16/3, 2018 at 13:45
2
Solved
There's a great tutorial here that seems to suggest to me that the Writer Monad is basically a special case tuple object that does operations on behalf of (A,B). The writer accumulates values on th...
Allies asked 29/5, 2014 at 20:58
1
Solved
I can't grasp the correct way of interrupting lengthy pure computation on SIGINT signal.
In the simple example below, I have slowFib function that simulates lengthy computation. When it is run ju...
Biquarterly asked 14/10, 2017 at 14:54
1
Solved
In Integrating State with Either (slide 88), given the pattern of State layered under Either, is there a recommended approach for adding another type of state, e.g., logging via something like Writ...
Pavis asked 8/1, 2017 at 18:9
2
Solved
I'm utterly confused between
newtype StateT s m a = StateT {runStateT :: s -> m (a, s)}
and
type State s = StateT s Identity
and
class Monad m => MonadState s m | m -> s
Statis asked 16/4, 2017 at 15:34
1
Context: I need to write a mostly stateless compiler which transforms VM bytecode into machine codes. Most VM commands can be translated statelessly with pure function like the following:
compile...
Vociferant asked 1/3, 2017 at 12:15
4
Solved
I am a JavaScript developer on a journey to up my skills in functional programming. I recently ran into a wall when it comes to managing state. When searching for a solution I stumbeled over the st...
Masto asked 29/1, 2015 at 20:46
3
Solved
An idiom I use for composing a couple of procedures (with memory) is as follows:
p1 :: State (Int, String) ()
p1 = do
(a, b) <- get
... do something ...
put (a', b)
p2 :: State (Int, String...
Traverse asked 10/11, 2016 at 8:49
2
Solved
As I'm learning for my exam Functional Programming, I'm still trying to really understand Monads. What better way than to define one yourself? I defined this:
newtype ST a = ST (State -> ([a], ...
Schuman asked 8/11, 2016 at 21:3
3
I'm currently writing a Haskell program that involves simulating an abstract machine, which has internal state, takes input and gives output. I know how to implement this using the state monad, whi...
Intercommunion asked 2/10, 2016 at 3:50
1
Solved
I'm a beginner at Haskell and I've come across a situation where I would like to use the state monad. (Or at least, I think I that's what I'd like to use.) There are a million tutorials for the sta...
Vitriolic asked 1/10, 2016 at 14:24
1 Next >
© 2022 - 2024 — McMap. All rights reserved.