えび (ebi_chan)
@えび (ebi_chan) has joined the channel
newtype X a = X {unX = ReaderT A IO a}
deriving
(MonadReader A)
newtype Y a = Y {unY = ReaderT B X a}
deriving
(
--MonadReader A -- 複数のMonadReaderにはできない
--MonadReader B
)
class MonadReader A => C1 where ...
class MonadReader B => C2 where ...
-- YをMonadReader A,Bどちらを要求するコンテキスト下でも使いたい。
Another solution to many of the same problems has been known for a while: free monads and extensible effects. As it happens, capability and free monads can be formally compared. In this paper, Mauro Jaskelioff and Russell O'Connor, prove that free monads are a special case of capabilities (it's not phrased in these terms, of course, but that's what the paper amounts to).
MonadReader a => 制約の掛かった関数に渡したい、という用途であれば (->) a がMonadReaderになる事が利用できるかもしれません。適当にラムダ式でくるめば型が合うかもnewtype YA a = YA (Y a) deriving (MonadReader A) newtype YB a = YB (Y a) deriving (MonadReader B) askA = coerce (ask @A @YA) askB = coerce (ask @B @YB)
capability なので,そっちを使える状況ならそっちを使う方がいいと思いますがclass 型クラス 型 where 条件式 instance 型クラス 型 where 条件式