4 ms·
Coming from Haskell, this seems a lot like taking the entire state of the world, sans I/O, and just bundling it into a monad (or MonadPlus, etc). Powerful, but
by rntz 17y ago
Coming from Haskell, this seems a lot like taking the entire state of the world, sans I/O, and just bundling it into a monad (or MonadPlus, etc). Powerful, but a bit of a blunt instrument compared to using a finer-grained technique. The backtracking use-case given of trying two keys to open a safe, for example, is straightfoward to solve with the List monad.
import OutsideWorld (keyA, keyB, unlocksSafe)
unlockSafe = do
key <- [keyA, keyB]
if unlocksSafe key then return key else mzero
Of course, in Haskell, this would be more idiomatically solved simply using filter; but it's a toy example after all.