DeepArrow 0.3.5 → 0.3.7
raw patch · 5 files changed
+84/−50 lines, 5 filesdep ~TypeCompose
Dependency ranges changed: TypeCompose
Files
- COPYING +25/−0
- DeepArrow.cabal +20/−13
- src/Control/Arrow/DeepArrow.hs +31/−35
- src/Control/Arrow/DeepArrow/Examples.hs +5/−1
- src/Data/DDeepArrow.hs +3/−1
+ COPYING view
@@ -0,0 +1,25 @@+Copyright (c) 2009-2012 Conal Elliott+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+3. The names of the authors may not be used to endorse or promote products+ derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+
DeepArrow.cabal view
@@ -1,7 +1,8 @@ Name: DeepArrow-Version: 0.3.5+Version: 0.3.7 Synopsis: Arrows for "deep application" Category: Combinators, Control+Cabal-Version: >= 1.6 Description: This library provides a framework for type-directed composition of value editors (non-syntactic transformations). The tools enable \"deep function@@ -29,19 +30,25 @@ © 2007-2012 by Conal Elliott (<http://conal.net>); BSD3 license. Author: Conal Elliott <conal@conal.net> Maintainer: conal@conal.net+Copyright: (c) 2007-2012 by Conal Elliott Homepage: http://haskell.org/haskellwiki/DeepArrow-Package-Url: http://code.haskell.org/~conal/code/DeepArrow License: BSD3+License-File: COPYING Stability: experimental-Copyright: (c) 2007-2012 by Conal Elliott Build-type: Simple-Hs-Source-Dirs: src-Build-Depends: base<5, mtl, TypeCompose>=0.6.7, haskell-src-Exposed-Modules: - Control.Arrow.DeepArrow- Data.FunArr- Data.DDeepArrow- Language.Haskell.ToHs- Language.Haskell.Parens- Control.Arrow.DeepArrow.Examples-ghc-options: -Wall++source-repository head+ type: git+ location: git://github.com/conal/DeepArrow.git++Library+ Hs-Source-Dirs: src+ Build-Depends: base<5, mtl, TypeCompose>=0.9.5, haskell-src+ Exposed-Modules: + Control.Arrow.DeepArrow+ Data.FunArr+ Data.DDeepArrow+ Language.Haskell.ToHs+ Language.Haskell.Parens+ Control.Arrow.DeepArrow.Examples+ ghc-options: -Wall
src/Control/Arrow/DeepArrow.hs view
@@ -30,9 +30,11 @@ , (->|) ) where +import Prelude hiding (id,(.))+import Control.Category import Control.Arrow -import Control.Compose ((::*::)(..),inProdd,FunA(..),inFunA, FunAble)+import Control.Compose ((::*::)(..),(*::*),inProdd,FunA(..),inFunA, FunAble) import Data.FunArr @@ -49,7 +51,6 @@ implementations @- 'idA' = 'arr' 'id' 'fstA' = 'arr' 'fst' 'dupA' = 'arr' (\\ x -> (x,x)) 'sndA' = 'arr' 'snd'@@ -70,7 +71,7 @@ ping-ponging infinitely between them via the 'Arrow' default definitions). @- 'second' f = 'swapA' '>>>' 'first' f '>>>' 'swapA'+ 'second' f = 'swapA' '.' 'first' f '.' 'swapA' f '&&&' g = 'dupA' '>>>' f '***' g @ @@ -86,8 +87,9 @@ -- Complicates OFun considerably and not used. -- Direct arrow into a function's argument. Note contravariance. -- argument :: (a' ~> a ) -> ((a->b) ~> (a'->b))- -- | Identity.- idA :: a ~> a+-- -- | Identity. Unnecessary now that we have Category +-- idA :: a ~> a+-- idA = id -- | Duplicate. dupA :: a ~> (a,a) -- | Extract first.@@ -109,18 +111,15 @@ swapA = sndA &&& fstA -- | Left-associate. Has default. lAssocA :: (a,(b,c)) ~> ((a,b),c)- lAssocA = (idA***fstA) &&& (sndA>>>sndA)+ lAssocA = second fstA &&& (sndA . sndA) -- | Right-associate. Has default. rAssocA :: ((a,b),c) ~> (a,(b,c))- rAssocA = (fstA>>>fstA) &&& (sndA *** idA)+ rAssocA = (fstA . fstA) &&& first sndA -- I don't think this one is used. -- composeA :: Arrow (~~>) => (a ~~> b, b ~~> c) ~> (a ~~>c) -- composeA = arr (uncurry (>>>)) --- TODO: eliminate idA, now that Arrow derives from Category, which has--- id. - {---------------------------------------------------------- Composable function extractors ----------------------------------------------------------}@@ -137,9 +136,9 @@ -- element of a function. funResult :: DeepArrow (~>) => (b ~> (d->b')) -> ((a->b) ~> (d->(a->b'))) -funFirst h = first h >>> funF-funSecond h = second h >>> funS-funResult h = result h >>> funR+funFirst h = funF . first h+funSecond h = funS . second h+funResult h = funR . result h {----------------------------------------------------------@@ -152,7 +151,7 @@ -- | Extract the second component of a pair input. inpS :: DeepArrow (~>) => ((a,b) -> c) ~> (b -> (a->c))-inpS = curryA >>> flipA+inpS = flipA . curryA -- | Given a way to extract a @d@ input from an @a@ input, leaving an @a'@@@ -170,11 +169,9 @@ -- See ICFP 07 paper for the derivation of inpFirst and inpSecond -inpFirst h = curryA >>> flipA >>> result h >>> flipA >>>- result (flipA>>>uncurryA)+inpFirst h = result (uncurryA . flipA) . flipA . result h . flipA . curryA -inpSecond h = curryA >>> result h >>> flipA >>>- result uncurryA+inpSecond h = result uncurryA . flipA . result h . curryA {----------------------------------------------------------@@ -187,7 +184,7 @@ -- | Like 'unzip' but for 'DeepArrow' arrows instead of lists. unzipA :: DeepArrow (~>) => (a ~> (b,c)) -> (a ~> b, a ~> c)-unzipA f = (f >>> fstA, f >>> sndA)+unzipA f = (fstA . f, sndA . f) {----------------------------------------------------------@@ -198,7 +195,7 @@ result = (.) -- argument = flip (.) -- Since (->) implements 'arr', use the recommended defaults for the rest.- idA = arr id+ -- idA = arr id fstA = arr fst dupA = arr (\x->(x,x)) sndA = arr snd@@ -214,22 +211,21 @@ -- DeepArrow "pairs" are deep arrows instance (DeepArrow ar, DeepArrow ar') => DeepArrow (ar ::*:: ar') where- idA = Prodd (idA, idA)- dupA = Prodd (dupA, dupA)- fstA = Prodd (fstA, fstA)- sndA = Prodd (sndA, sndA)- funF = Prodd (funF, funF)- funS = Prodd (funS, funS)- funR = Prodd (funR, funR)- curryA = Prodd (curryA, curryA)- uncurryA = Prodd (uncurryA, uncurryA)- swapA = Prodd (swapA, swapA)- lAssocA = Prodd (lAssocA, lAssocA)- rAssocA = Prodd (rAssocA, rAssocA)+ dupA = dupA *::* dupA+ fstA = fstA *::* fstA+ sndA = sndA *::* sndA+ funF = funF *::* funF+ funS = funS *::* funS+ funR = funR *::* funR+ curryA = curryA *::* curryA+ uncurryA = uncurryA *::* uncurryA+ swapA = swapA *::* swapA+ lAssocA = lAssocA *::* lAssocA+ rAssocA = rAssocA *::* rAssocA result = inProdd (result *** result)- -- result (Prodd (f,f')) = Prodd (result f, result f') + -- idA = idA *::* idA -- composeA = Prodd (composeA, composeA) -- argument (Prodd (f,f')) = Prodd (argument f, argument f') @@ -253,7 +249,7 @@ instance FunDble h => DeepArrow (FunA h) where result = inFunA resultFun- idA = FunA id+ -- idA = FunA id dupA = FunA dupAFun fstA = FunA fstAFun sndA = FunA sndAFun@@ -286,4 +282,4 @@ -- -- | Pre- and post-processing -- (~>) :: DeepArrow (-->) => (a' --> a) -> (b --> b') -> ((a -> b) --> (a' -> b'))--- f ~> h = result h >>> argument f+-- f ~> h = result h . argument f
src/Control/Arrow/DeepArrow/Examples.hs view
@@ -27,6 +27,10 @@ , extI, extFI ) where +import Prelude ()+-- import Prelude hiding (id,(.))++import Control.Category import Control.Arrow import Control.Arrow.DeepArrow @@ -67,7 +71,7 @@ extFF :: DeepArrow (~>) => (e -> (a,(c-> b)),f) ~> (c -> (e -> (a, b),f))-extFF = extF idA+extFF = extF id {----------------------------------------------------------
src/Data/DDeepArrow.hs view
@@ -89,11 +89,13 @@ uncurryA = UncurryA lAssocA = LAssocA rAssocA = RAssocA- idA = IdA dupA = DupA fstA = FstA sndA = SndA swapA = SwapA++ -- idA = IdA+ -- | A GADT alternative to terms. Allows generation of Haskell terms and, -- from there, strings and eval.