[Haskell-cafe] Unambiguous choice implementation

Heinrich Apfelmus apfelmus at quantentunnel.de
Sun Jun 24 16:21:07 CEST 2012

Bartosz Milewski wrote:
> I'm reading Conal Elliot's paper, Push-Pull FRP. At some point he needs an
> unambiguous choice operator, essentially to implement select: a future that
> waits for one of its future arguments to fire. His implementation of unamb
> creates two threads racing on a shared MVar. By his own admission, this is
> very inefficient. My question is, is there a better implementation?

The thing about unambiguous choice is that it goes beyond the dynamic 
semantics of the Haskell language. To implement it, you either need a 
new evaluation model built into the compiler, or you have to fake it 
somehow and that is likely to be inefficient.

Also note that Conal's paper describes just one possible implementation 
of FRP. My reactive-banana library uses an implementation that doesn't 
require unambiguous choice at all. For a basic model, see


The key idea is to keep all events synchronous and to reify some cases 
of "this event does not occur right now".

Best regards,
Heinrich Apfelmus


More information about the Haskell-Cafe mailing list