[英]A Reader monad for multiple arguments?
Is there an equivalent to the Reader
monad that's equivalent to a -> b -> c
rather than just a -> b
.是否有等效于
a -> b -> c
而不仅仅是a -> b
的Reader
monad。 I know I could do (a, b) -> c
but I'm not sure that's going to be very ergonomic.我知道我可以做
(a, b) -> c
但我不确定这是否符合人体工程学。
The only way to make that a monad is by wrapping it which may not be what you're after.使它成为 monad 的唯一方法是包装它,这可能不是您想要的。 The instance can be derived
可以推导出实例
{-# Language DerivingVia #-}
import Control.Monad.Reader
newtype Reader2 a b c = Reader2 (a -> b -> c)
deriving (Functor, Applicative, Monad, MonadFix, MonadReader a)
via ReaderT a ((->) b)
If you derive Representable
it witnesses the isomorphism between Reader2 ab c
and (a, b) -> c
如果你派生
Representable
它见证了Reader2 ab c
和(a, b) -> c
之间的同构
index :: Reader2 a b c -> ((a, b) -> c)
tabulate :: ((a, b) -> c) -> Reader2 a b c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.