packages feed

Kriens 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+9/−81 lines, 2 files

Files

Kriens.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.0+version:             0.1.0.1  -- A short (one-line) description of the package. synopsis:            Category for Continuation Passing Style
src/Control/Category/Cont.hs view
@@ -12,7 +12,8 @@ Portability :  portable -} -module Control.Category.Cont ( -- * The Cont category+module Control.Category.Cont ( -- $Remark+                               -- * The Cont category                                -- $Category                                 -- ** Category laws@@ -23,21 +24,18 @@                              , withCont                              , lift                              , cont-                             -- * Example: Composable sorter-                             -- $Example1-                             -                             -- * Example: Composable actions-                             -- $Example2--                             -- * Example: Monoid-                             -- $Example3                              ) where  import Prelude hiding (id, (.)) import Control.Category import Data.Monoid +{-$Remark+This package provides a new type for the Continuation catgory. Often is anyway easier to use plain functions.+-}+ {-$Category+ The Continuation category is defined as follow:  - object are functions of the type @f :: a -> b@, @g :: c -> d@.@@ -53,7 +51,7 @@ - Identity law: @'Cont' f . 'Cont' 'id' = 'Cont' f . 'id' = 'Cont' 'f' = 'Cont' 'id' . f = 'Cont' 'id' . 'Cont' f@ - Associativity law:-@('Cont' f . 'Cont' g) . 'Cont' h = 'Cont' (f . g) . 'Cont' h = 'Cont' (f . g . h) = 'Cont' (f . (g . h)) = 'Cont' f . 'Cont' (g .h) = 'Cont' f . ('Cont' g . 'Cont' h)@+@('Cont' f . 'Cont' g) . 'Cont' h = 'Cont' (f . g) . 'Cont' h = 'Cont' (f . g . h) = 'Cont' (f . (g . h)) = 'Cont' f . 'Cont' (g . h) = 'Cont' f . ('Cont' g . 'Cont' h)@ -}  -- |A type for the Continuation category.@@ -82,73 +80,3 @@ -- |Lift the continuation into a Monad. lift :: Monad m => Cont (a -> b) (a -> m b) lift = withCont return--{-$Example1-Here is an example how to use the @Cont@ category to compose a custom sorter:-->import Prelude hiding (id, (.))->import Control.Category->import Control.Category.Cont->import Data.List->->data User = User { name :: String->                  , surname :: String->                  , yob :: Int->                  } deriving Show->->users = [ User { name = "Amadeus", surname = "Mozart", yob = 1756 }->        , User { name = "Amadeus", surname = "Brahms", yob = 1833 }->        , User { name = "Johannes", surname = "Brahms", yob = 1833 }->        , User { name = "Johannes", surname = "Mozart", yob = 1833 }->        , User { name = "Antonio", surname = "Vivaldi", yob = 1678 }->        , User { name = "Antonio", surname = "Vivaldi", yob = 1679 }->        ]->->order = cont $ \f x -> sortBy (curry f) x ->by field = cont $->   \f x -> if ord x == EQ then->              f x->           else->              ord x->        where->           ord x = compare ((field . fst) x) ((field . snd) x)->->eqOtherwise = cont $ \f x -> EQ->->mysort = forget $ order . (by surname) . (by name) . (by yob) . eqOtherwise--}-{-$Example2-Here is an example how to combine the Cont category with the @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--The action @withPassword@ requests the 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.--}-{-$Example3->import Prelude hiding (id, (.))->import Control.Category->import Control.Category.Cont->->ins a = [a]->select op = cont $->    \f x -> f $ op x->->toList :: (a, a) -> [a]->toList = forget $  (select fst `mappend` select snd) . (withCont ins)--}