ekmett / free

free monads
http://hackage.haskell.org/package/free
Other
159 stars 65 forks source link

Add specialization of `retract` for `Iter ~ IterT Identity` #75

Open vlopezj opened 10 years ago

vlopezj commented 10 years ago

When using the Iter monad, it is common to, at some point, run the computation until it terminates by using runIdentity . retract.

This could be implemented as a separate function, named, for example unsafeIter :: Iter a -> a, in the same spirit as fromMaybe :: Maybe a -> a or unsafePerformIO :: IO a -> a. The unsafe monicker warns that the safety guarantees from the Iter monad are lost, namely, evaluation might not terminate.

Any input on the name, the implementation or the usefulness of the proposed function is welcome.

ekmett commented 9 years ago

I'm not so keen on the 'unsafe' name, but I have no objection to adding an operation with a name that clearly indicates it runs to completion.

vlopezj commented 9 years ago

How about whileRight or untilLeft? Either standalone, or prefixed with run, runIter or iter.

The probability package uses untilLeft [1]. According to Google, the other alternatives are not used by any other Hackage package.

[1] https://hackage.haskell.org/package/probability-0.2.4.1/docs/Numeric-Probability-Transition.html