Final library makes it possible to point out return values in
(monadic) functions. This adds extra compile-time safety to your
code, because the compiler will warn you if marked return values
accidentally became middle parts of a big function written with do
- final :: (Monad m, FinalClass f) => x -> m (f x)
- runFinal :: Monad m => m (Final a) -> m a
- joinFinal :: Monad m => m (Final (m a)) -> m a
- atomicJoinFinal :: (Functor m, MonadIO m) => STM (Final (m a)) -> m a
- atomic :: MonadIO m => STM a -> m a
- class FinalClass f where
- finalV :: a -> f a
- runFinalV :: Final a -> a
Most common, monadic usage
Most commonly used at the beginning of functions to mark the
point in the code where
final calls "return to".
simple = runFinal $ do print "line1" do return False return True final True
This fails at the first "
simple = runFinal $ do print "line1" do return False final True final True
Useful when the final return value is a monadic computation itself that after returned has to be joined into the current computation.
A version of atomically, that joins and runFinals. This is the most common usage for the author. Details and example can be found in Control.Final.Example.
MonadIO version of atomically. Not really related to
but if we already have
atomicJoinFinal in this module, it makes
sense to provide this too.
Usage in pure code
This class is the main idea behind
finalV is in a
type class, so we we can have to instances, therefore if used
incorrectly the compiler sees an ambiguity.