Copyright | (c) Matteo Provenzano 2015 |
---|---|
License | BSD-style (see the LICENSE file in the distribution) |
Maintainer | matteo.provenzano@alephdue.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Documentation
A type for the Continuation category. In the Continuation category:
- object are functions
f :: a -> b
,g :: c -> d
- arrows are functions
t :: (a -> b) -> (c -> d)
Example: Using Cont
category
ContT
can be used to add continuation handling to other monads.
Here is an example how to combine it with IO
monad:
import Prelude hiding (id, (.)) import Control.Category import Control.Category.Cont
withPassword pwd = cont $ \f x -> do putStrLn "Enter the secret password:" pass <- getLine if pass == pwd then f x else return "you are not authorized to execute this action."
greet = cont $ \f x -> f $ "hello to " ++ x
secureGreet = forget $ (withPassword "secret") . lift . greet verySecureGreet = forget $ (withPassword "secret") . (withPassword "verySecret") . lift . greet
Action withPassword
requests user to enter a string. If the string matches the password the input is handed to the continuation.
lift
is used to inject the pure code into the IO monad.