3 ms·
You can implement 'amb' using either continuations or monads. Back in 2005, I wrote a very short Ruby version of 'amb' using continuations: http://www.randomha
by ekidd 6y ago
You can implement 'amb' using either continuations or monads.
Back in 2005, I wrote a very short Ruby version of 'amb' using continuations: http://www.randomhacks.net/2005/10/11/amb-operator/ http://www.randomhacks.net/2005/10/11/amb-operator/ This approach works if your code contains no side effects, because it involves backtracking and restarting the computation as needed. But continuations are a heavyweight feature that place significant constraints on language implementation, so few languages support them.
You can also implement 'amb' using monads: http://www.randomhacks.net/2007/03/12/monads-in-15-minutes/ http://www.randomhacks.net/2007/03/12/monads-in-15-minutes/ (Yes, this is yet another monad tutorial. Sorry.) This benefits from a "do notation" syntax, which could be implemented using macros.