Zustands-Transformatoren

data State s a = State ( s -> (a, s) )

next :: State [b] b
next = State $ \ xs -> (head xs, tail xs)

instance Monad ( State s ) where
    return x = State $ \ s -> ( x, s )
    State f >>= g = State $ \ s ->
        let (a, t) = f s ; State h = g a  
        in  h t

evalState :: State s a -> s -> a
evalState (State f) s = let (a,t) = f s in a



Johannes Waldmann 2011-01-18