learnyouahaskell / learnyouahaskell.github.io

A community version of the renowned "Learn You a Haskell" (LYAH) tutorials collection!
https://learnyouahaskell.github.io
Other
299 stars 35 forks source link

State monad #43

Closed gilesbradshaw closed 1 year ago

gilesbradshaw commented 1 year ago

Is your content edit request related to a problem? Please describe.

Some of the state monad stuff doesnlt comiple as State is not exported from Control.Monad.State

Describe the solution you'd like state in lower case:

type Stack = [Int]

pop :: State Stack Int  
pop = state $ \(x:xs) -> (x,xs)  

push :: Int -> State Stack ()  
push a = state $ \xs -> ((),a:xs)  

Additional context

https://stackoverflow.com/questions/9697980/the-state-monad-and-learnyouahaskell-com Link to the page in question

https://learnyouahaskell.github.io/for-a-few-monads-more.html#state

MatthijsBlom commented 1 year ago

Duplicate of #7.