да newtype FromMonad m a = FromMonad (m a) deriving Monad instance Monad m => Functor (FromMonad m) where fmap = liftM instance Monad m => Applicative (FromMonad m) where pure = return (<*>) = ap data Stream a b = Done b | Yield a (Stream a b) deriving (Functor, Applicative) via (FromMonad(Stream a)) instance Monad (Stream a) where return = Done Yield a k >>= f = Yield a (k >>= f) Done b >>= f = f b
Обсуждают сегодня