-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Arrows for "deep application" -- -- This library provides a framework for type-directed composition of -- value editors (non-syntactic transformations). The tools enable "deep -- function application" in two senses: deep application of functions and -- application of deep functions. These tools generalize beyond values -- and functions, via the DeepArrow subclass of the -- Arrow type class. -- -- For more information see: -- -- -- -- This page and the module documentation pages have links to colorized -- source code and to wiki pages where you can read and contribute /user -- comments/. Enjoy! -- -- The primary module is Control.Arrow.DeepArrow. Examples in -- Control.Arrow.DeepArrow.Examples. -- -- Note: Many of the type signatures use infix type operators (as -- in a~>b), a recent extension to GHC. In reading the -- documentation and code, be aware that infix operators bind more -- tightly than ->. -- -- © 2007 by Conal Elliott (http://conal.net); BSD3 license. @package DeepArrow @version 0.3.3 -- | Insert parens where necessary in Haskell expressions. Inspired by -- Sigbjorn Finne's Pan pretty-printer. module Language.Haskell.Parens pretty :: HsExp -> String type Cify a = a -> (Context -> a) cifyExp :: Cify HsExp unCify :: (Context -> a) -> a hasOpInfo :: HsName -> Bool instance Eq Assoc -- | Convert values to Haskell abstract syntax module Language.Haskell.ToHs -- | Conversion to Haskell expressions class ToHsExp a toHsExp :: ToHsExp a => a -> HsExp varid :: String -> HsExp varsym :: String -> HsExp toHsApp1 :: ToHsExp a => String -> a -> HsExp toHsApp2 :: (ToHsExp a, ToHsExp b) => String -> a -> b -> HsExp infixApp :: HsName -> HsExp -> HsExp -> HsExp toHsInfix :: (ToHsExp a, ToHsExp b) => HsName -> a -> b -> HsExp prettyAsHsExp :: ToHsExp a => a -> String instance ToHsExp Bool instance ToHsExp Double instance ToHsExp Float instance ToHsExp Int instance ToHsExp String instance ToHsExp Char -- | Conversion between arrow values and wrapped functions. module Data.FunArr -- | Convert between an arrow value and a "wrapped function". The "arrow" -- doesn't really have to be an arrow. I'd appreciate ideas for names -- & uses. class FunArr ~> w | ~> -> w, w -> ~> toArr :: FunArr ~> w => w (a -> b) -> (a ~> b) ($$) :: FunArr ~> w => (a ~> b) -> w a -> w b instance (FunArr ar w, FunArr ar' w') => FunArr (ar ::*:: ar') (w :*: w') instance FunArr (->) Id -- | "Deep arrows" as an Arrow subclass. module Control.Arrow.DeepArrow -- | Arrows for deep application. Most of these methods could be defined -- using arr, but arr is not definable for some types. If -- your DeepArrow instance has arr, you might want to use -- these implementations -- --
--   idA      = arr id
--   fstA     = arr fst
--   dupA     = arr (\ x -> (x,x))
--   sndA     = arr snd
--   funF     = arr (\ (f,b) -> \ c -> (f c, b))
--   funS     = arr (\ (a,f) -> \ c -> (a, f c))
--   funR     = arr flip
--   curryA   = arr curry
--   uncurryA = arr uncurry
--   swapA    = arr (\ (a,b) -> (b,a))
--   lAssocA  = arr (\ (a,(b,c)) -> ((a,b),c))
--   rAssocA  = arr (\ ((a,b),c) -> (a,(b,c)))
--   
-- -- If your DeepArrow instance does not have arr, -- you'll have to come up with other definitions. In any case, I -- recommend the following definitions, which mirror Arrow -- defaults while avoiding arr. Be sure also to define arr -- or pure to yield an error message (rather than ping-ponging -- infinitely between them via the Arrow default definitions). -- --
--   second f = swapA >>> first f >>> swapA
--   f &&& g  = dupA  >>> f *** g
--   
-- -- In a few cases, there are default methods, as noted below. The -- defaults do not use arr. class Arrow ~> => DeepArrow ~> result :: DeepArrow ~> => (b ~> b') -> ((a -> b) ~> (a -> b')) idA :: DeepArrow ~> => a ~> a dupA :: DeepArrow ~> => a ~> (a, a) fstA :: DeepArrow ~> => (a, b) ~> a sndA :: DeepArrow ~> => (a, b) ~> b funF :: DeepArrow ~> => (c -> a, b) ~> (c -> (a, b)) funS :: DeepArrow ~> => (a, c -> b) ~> (c -> (a, b)) funR :: DeepArrow ~> => (a -> c -> b) ~> (c -> a -> b) curryA :: DeepArrow ~> => ((a, b) -> c) ~> (a -> b -> c) uncurryA :: DeepArrow ~> => (a -> b -> c) ~> ((a, b) -> c) swapA :: DeepArrow ~> => (a, b) ~> (b, a) lAssocA :: DeepArrow ~> => (a, (b, c)) ~> ((a, b), c) rAssocA :: DeepArrow ~> => ((a, b), c) ~> (a, (b, c)) -- | Promote a function extractor into one that reaches into the first -- element of a pair. funFirst :: DeepArrow ~> => (a ~> (d -> a')) -> ((a, b) ~> (d -> (a', b))) -- | Promote a function extractor into one that reaches into the second -- element of a pair. funSecond :: DeepArrow ~> => (b ~> (d -> b')) -> ((a, b) ~> (d -> (a, b'))) -- | Promote a function extractor into one that reaches into the result -- element of a function. funResult :: DeepArrow ~> => (b ~> (d -> b')) -> ((a -> b) ~> (d -> (a -> b'))) -- | Extract the first component of a pair input. inpF :: DeepArrow ~> => ((a, b) -> c) ~> (a -> (b -> c)) -- | Extract the second component of a pair input. inpS :: DeepArrow ~> => ((a, b) -> c) ~> (b -> (a -> c)) -- | Given a way to extract a d input from an a input, -- leaving an a' residual input, inpFirst yields a way to -- extract a d input from an (a,b) input, leaving an -- (a',b) residual input. inpFirst :: DeepArrow ~> => ((a -> c) ~> (d -> (a' -> c))) -> (((a, b) -> c) ~> (d -> ((a', b) -> c))) -- | Analogous to inpFirst. inpSecond :: DeepArrow ~> => ((b -> c) ~> (d -> (b' -> c))) -> (((a, b) -> c) ~> (d -> ((a, b') -> c))) -- | Flip argument order flipA :: DeepArrow ~> => (a -> c -> b) ~> (c -> a -> b) -- | Like unzip but for DeepArrow arrows instead of lists. unzipA :: DeepArrow ~> => (a ~> (b, c)) -> (a ~> b, a ~> c) -- | Support needed for a FunA to be a DeepArrow (as -- FunAble serves Arrow). class FunAble h => FunDble h resultFun :: FunDble h => (h b -> h b') -> (h (a -> b) -> h (a -> b')) dupAFun :: FunDble h => h a -> h (a, a) fstAFun :: FunDble h => h (a, b) -> h a sndAFun :: FunDble h => h (a, b) -> h b funFFun :: FunDble h => h (c -> a, b) -> h (c -> (a, b)) funSFun :: FunDble h => h (a, c -> b) -> h (c -> (a, b)) funRFun :: FunDble h => h (a -> c -> b) -> h (c -> a -> b) curryAFun :: FunDble h => h ((a, b) -> c) -> h (a -> b -> c) uncurryAFun :: FunDble h => h (a -> b -> c) -> h ((a, b) -> c) swapAFun :: FunDble h => h (a, b) -> h (b, a) lAssocAFun :: FunDble h => h (a, (b, c)) -> h ((a, b), c) rAssocAFun :: FunDble h => h ((a, b), c) -> h (a, (b, c)) -- | Compose wrapped functions (->|) :: (DeepArrow ~>, FunArr ~> w) => w (a -> b) -> w (b -> c) -> w (a -> c) instance FunDble h => DeepArrow (FunA h) instance (DeepArrow ar, DeepArrow ar') => DeepArrow (ar ::*:: ar') instance DeepArrow (->) -- | "Deep arrows" as a data type. Handy for code generation. module Data.DDeepArrow -- | This GADT mirrors the DeepArrow class and part of the -- FunArr class. data DArrow :: * -> * -> * Arr :: DVal (a -> b) -> a DArrow b Compose :: a DArrow b -> b DArrow c -> a DArrow c First :: a DArrow a' -> (a, b) DArrow (a', b) Second :: b DArrow b' -> (a, b) DArrow (a, b') Result :: b DArrow b' -> (a -> b) DArrow (a -> b') FunF :: (c -> a, b) DArrow (c -> (a, b)) FunS :: (a, c -> b) DArrow (c -> (a, b)) FunR :: (a -> c -> b) DArrow (c -> a -> b) CurryA :: ((a, b) -> c) DArrow (a -> b -> c) UncurryA :: (a -> b -> c) DArrow ((a, b) -> c) LAssocA :: (a, (b, c)) DArrow ((a, b), c) RAssocA :: ((a, b), c) DArrow (a, (b, c)) IdA :: a DArrow a DupA :: a DArrow (a, a) FstA :: (a, b) DArrow a SndA :: (a, b) DArrow b SwapA :: (a, b) DArrow (b, a) -- | A GADT alternative to terms. Allows generation of Haskell terms and, -- from there, strings and eval. data DVal :: * -> * ExpDV :: HsExp -> DVal a AppDA :: a DArrow b -> DVal a -> DVal b ZipDV :: DVal a -> DVal b -> DVal (a, b) instance Show (DVal a) instance Show (DArrow a b) instance FunArr DArrow DVal instance ToHsExp (DVal a) instance ToHsExp (DArrow a b) instance Zip DVal instance DeepArrow DArrow instance Arrow DArrow instance Category DArrow -- | DeepArrow examples. -- -- The types in the source code are formatted for easier reading. module Control.Arrow.DeepArrow.Examples -- | Given a value of type (a -> (f,b -> (c,g)),e), apply a -- function to just the c part and leave the rest intact. -- --
--   deep = first . result . second . result . first
--   
deep :: DeepArrow ~> => (c ~> c') -> (a -> (f, b -> (c, g)), e) ~> (a -> (f, b -> (c', g)), e) -- | Given a way to extract a function from a d value, create a -- way to extract a function from a (e -> (a,d), f) value. -- --
--   extF = funFirst . funResult . funSecond
--   
extF :: DeepArrow ~> => (d ~> (c -> b)) -> (e -> (a, d), f) ~> (c -> (e -> (a, b), f)) -- | To make an extractor, simply apply the extractor-transformer -- extF to the identity arrow. -- --
--   extFF = extF idA
--   
extFF :: DeepArrow ~> => (e -> (a, c -> b), f) ~> (c -> (e -> (a, b), f)) -- | Extract a b input from a ((a,(b,e)),c) argument. -- --
--   extI = (inpFirst . inpSecond) inpF
--   
extI :: DeepArrow ~> => (((a, (b, e)), c) -> d) ~> (b -> ((a, e), c) -> d) -- | Typically, we will have to combine function and input extractors. For -- instance, combine extF and extI. -- --
--   extFI = extF extI
--   
extFI :: DeepArrow ~> => (e -> (g, ((a, (b, e)), c) -> d), f) ~> (b -> (e -> (g, ((a, e), c) -> d), f))