VS
А в целом коллега достаточно не мейнстримовый программист, ЕМНИП
Size: a a a
VS
R
newtype Writer w a = Writer { runWriter :: (a, w) } deriving Show
instance Functor (Writer w) where
fmap f (Writer (a, w)) = Writer (f a, w)
instance Monoid w => Applicative (Writer w) where
pure a = Writer (a, mempty)
Writer (f, w) <*> Writer (a, w') = Writer (f a, w <> w')
instance Monoid w => Monad (Writer w) where
return = pure
Writer (a, w) >>= f = let (b, w') = runWriter (f a) in Writer (b, w <> w')
tell :: w -> Writer w ()
tell w = Writer ((), w)
half :: Int -> Writer String Int
half x = do
tell ("I just halved " ++ show x ++ "!")
return (x `div` 2)
Writer {runWriter = (4,"I just halved 8!")}
pure a = Writer (a, mempty)
DG
newtype Writer w a = Writer { runWriter :: (a, w) } deriving Show
instance Functor (Writer w) where
fmap f (Writer (a, w)) = Writer (f a, w)
instance Monoid w => Applicative (Writer w) where
pure a = Writer (a, mempty)
Writer (f, w) <*> Writer (a, w') = Writer (f a, w <> w')
instance Monoid w => Monad (Writer w) where
return = pure
Writer (a, w) >>= f = let (b, w') = runWriter (f a) in Writer (b, w <> w')
tell :: w -> Writer w ()
tell w = Writer ((), w)
half :: Int -> Writer String Int
half x = do
tell ("I just halved " ++ show x ++ "!")
return (x `div` 2)
Writer {runWriter = (4,"I just halved 8!")}
pure a = Writer (a, mempty)
AP
R
AP
Monoid a => Writer a Int
DG
Monoid a => Writer a Int
AP
АВ
AP
AP
D
JS
A
A
к
Currency
не импортированык
к