module NewType where newtype ST s a = ST { unST :: s -> (a, s) } -- newtype ST s a = ST (s -> (a, s)) -- unST (ST m) = m unitST :: a -> ST s a unitST a = ST (\ s -> (a, s)) bindST :: ST s a -> (a -> ST s b) -> ST s b (ST m) `bindST` k = ST (\ s0 -> let (a, s1) = m s0 in unST (k a) s1) instance Monad (ST s) where return = unitST (>>=) = bindST