ContArrow 0.0.2 → 0.0.3
raw patch · 3 files changed
+59/−15 lines, 3 files
Files
- ContArrow.cabal +20/−15
- LICENSE +0/−0
- src/Control/Arrow/Transformer/Cont.hs +39/−0
ContArrow.cabal view
@@ -1,16 +1,21 @@-Name: ContArrow-Version: 0.0.2-License: LGPL-Maintainer: Evgeny Jukov <masloed@gmail.com>-Author: Evgeny Jukov-Stability: Alpha-Copyright: Copyright (c) 2007 Evgeny Jukov-license-file: COPYRIGHT-Homepage: http://macode.sourceforge.net-Synopsis: Control.Arrow.Transformer.Cont-description: Control.Arrow.Transformer.Cont-Category: Control-Hs-Source-Dirs: src+Name: ContArrow+Version: 0.0.3+License: LGPL+Maintainer: Evgeny Jukov <masloed@gmail.com>+Author: Evgeny Jukov+Stability: Alpha+Build-Type: Simple+Copyright: Copyright (c) 2007, 2008 Evgeny Jukov+license-file: LICENSE++Homepage: http://macode.sourceforge.net/ContArrow+Synopsis: Control.Arrow.Transformer.Cont+description: A library providing Control.Arrow.Transformer.Cont+Category: Control++Hs-Source-Dirs: src Exposed-Modules: Control.Arrow.Transformer.Cont-Build-Depends: base, arrows-GHC-Options: -O2+Tested-With: GHC+Build-Depends: base, arrows+Extensions: FlexibleInstances, MultiParamTypeClasses+GHC-Options: -O2 -Wall -Werror
+ LICENSE view
+ src/Control/Arrow/Transformer/Cont.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}+module Control.Arrow.Transformer.Cont where++import Control.Arrow+import Control.Arrow.Transformer (ArrowTransformer(), lift)++newtype ContArrow e a b c = CO (a c e -> a b e)++instance ArrowApply a => Arrow (ContArrow e a) where+ arr f = liftCont (arr f)+ CO f >>> CO g = CO (\k -> f (g k))+ first (CO f) = CO $ \k -> app <<^ \(b,d) ->+ (f (arr (\c -> (c,d)) >>> k), b)++instance ArrowApply a => ArrowChoice (ContArrow e a) where+ left (CO f) = CO $ \k -> app <<^ \x ->+ case x of+ Left b -> ((\(Left a) -> a) ^>> f (arr (\c -> Left c) >>> k), Left b)+ Right d -> ((\(Right a) -> a) ^>> id (arr (\c -> Right c) >>> k), Right d)++instance ArrowApply a => ArrowApply (ContArrow e a) where+ app = CO $ \k -> first (\(CO a) -> a k) ^>> app++liftCont :: Arrow a => a b c -> ContArrow e a b c+liftCont f = CO (\k -> f >>> k)++instance ArrowApply a => ArrowTransformer (ContArrow e) a where+ lift = liftCont++runCont :: ArrowApply a => ContArrow e a b c -> a c e -> a b e+runCont (CO f) = f+++jump :: ArrowApply a => ContArrow e a (a c e, c) z+jump = CO (\_ -> app)++callcc :: ArrowApply a+ => (a c e -> ContArrow e a b c) -> ContArrow e a b c+callcc f = CO (\k -> let CO g = f k in g k)