4

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))?

Kwarrtz
  • 2,693
  • 15
  • 24
  • 3
    The 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 Answers1

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