Actually, you can make a joinInner for the State monad. However, it
does not allow the inner function (h) to change the state, because how
state is threaded through a monad N is different for each N.
i :: (Monad n) = (a - State s b) - (b - n c) - (c - State s d) -
(a - State s (n d))
i f
I'm trying to make a function that uses another monadic function inside a
preexisting monad, and I'm having trouble.
Basically my problem boils down to this. I have three monadic functions with
the following types:
f :: A - M B
g :: B - N C
h :: C - M D
(M and N are in the monad class)
I want a
The problem you have is that monad composition isn't defined in general. You
would need some form of distributive law either for your monads in general,
or for your particular monads wrapped around this particular kind of value.
What I would look for is a function of the form of one of:
Yeah, I think the problem with my case is that while M is a specific monad
(essentially StateT), N can be an arbitrary monad, which I think destroys my
changes of making a valid joinInner/joinOuter/distribute.
Maybe someday Haskell will infer valid joinInner/joinOuter for simple cases
:D
Thanks
You can do this if D - M (N D) is a monad itself.
I suggest you study monad transformers - may be it's what you really
want.
On 10 Jul 2009, at 19:34, Job Vranish wrote:
I'm trying to make a function that uses another monadic function
inside a preexisting monad, and I'm having trouble.
Job Vranish wrote:
Yeah, I think the problem with my case is that while M is a specific monad
(essentially StateT), N can be an arbitrary monad, which I think destroys my
changes of making a valid joinInner/joinOuter/distribute.
Maybe someday Haskell will infer valid joinInner/joinOuter for