简体   繁体   English

多个 arguments 的 Reader monad?

[英]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 -> bReader 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM