I am using FRP.Sodium
and I have an object of type IO (Behavior (IO (Behavior)))
. I need to convert that object to type IO (Behavior)
, using something akin to a nested join
. Is this possible using Sodium functions? Is there a more general solution for a (b (a (b c))) -> a (b c))
?
Asked
Active
Viewed 135 times
4

Kwarrtz
- 2,693
- 15
- 24
-
3The non-existence of the general solution is discussed in [Applicatives compose, monads don't](http://stackoverflow.com/q/7040844/414413). – Cirdec Aug 25 '15 at 05:09
-
@Cirdec Yes, that offers a very comprehensive explanation. – Kwarrtz Aug 26 '15 at 01:50
1 Answers
6
There isn't an obvious way to do so. You could cobble together something with the right type using functions like sample
and sync
or updates
and executeSyncIO/executeAsyncIO
, but it probably wouldn't obey the Monad
laws.
There isn't a more general solution for a (b (a (b c))) -> a (b c))
, but there is if b
is Traversable
, which lets you rearrange things into a (a (b (b c)))
by traversing the outer b
.

Cirdec
- 24,019
- 2
- 50
- 100
-
I hadn't even considered `traverse`, that's just what I was looking for. – Kwarrtz Aug 25 '15 at 05:03