haskell - defining a State' monad which counts the Gets, Puts, Bind and Returns done on it -
I am trying to define a state monad state in Haskell
newtype State 's = state' {runState ':: (S, calculation) - & gt; (A, S, Count)} tracks the number of counts, gives returns and is done on it
data calculation = count {Binds:: int, return :: int, gets :: int, put :: int} deriving (one, shows) installation monoid cats where mempt = count 0 0 0 mappend (count x 1 x 2 x3 x 4 ) (Calculation y1 y2 y3 y4) = calculation (x1 + y1) (x2 + y2) (x3 + y3) (x4 + y4) I have been able to define return And for this new mondo =
return x = state 'f jah A. F = \ (s, count) - & gt; (X, s ', count') = runState 'st (s, count) (x, s, count & lt;> a return card ST> gt; = k = state' (\ (s, Count) in Runstrat (KX) (s, gin ' However, I am unable to get it and this state has received the' state ' And to do the same as getting it, still they need to increase the number one by one and the number one (the constant in which one gets and puts one)
Can someone help me To understand that How did it define good how much it was to get and put it for the state?
It seems that get back , but instead of s get the x
= state '$ \ (S, count)) - & gt; (S, S, Count & lt; & gt; One gate) then put is also like return , but new Set s .
enters s = 'state' $ \ (s, count) - & gt; ((), S ', count & lt;> oneput)
Comments
Post a Comment