class (Arrow a, ArrowPlus a, ArrowZero a, ArrowApply a) => ArrowList (a :: Type -> Type -> Type) whereThe interface for list arrows
Only mkA, isA (>>.) don't have default implementations
Methods
arr2 :: (b1 -> b2 -> c) -> a (b1, b2) cconstruction of a 2 argument arrow from a binary function | | example:
a1 &&& a2 >>> arr2 farr3 :: (b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) cconstruction of a 3 argument arrow from a 3-ary function | | example:
a1 &&& a2 &&& a3 >>> arr3 farr4 :: (b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) cconstruction of a 4 argument arrow from a 4-ary function | | example:
a1 &&& a2 &&& a3 &&& a4 >>> arr4 farr2A :: (b -> a c d) -> a (b, c) dconstruction of a 2 argument arrow from a singe argument arrow
arrL :: (b -> [c]) -> a b cconstructor for a list arrow from a function with a list as result
arr2L :: (b -> c -> [d]) -> a (b, c) dconstructor for a list arrow with 2 arguments
constA :: c -> a b cconstructor for a const arrow:
constA = arr . constconstL :: [c] -> a b cconstructor for a const arrow:
constL = arrL . constisA :: (b -> Bool) -> a b bbuilds an arrow from a predicate. If the predicate holds, the single list containing the input is returned, else the empty list
(>>.) :: a b c -> ([c] -> [d]) -> a b dinfixl 8combinator for converting the result of a list arrow into another list
example:
foo >>. reversereverses the the result of fooexample:
foo >>. take 1constructs a deterministic version of foo by deleting all further results(>.) :: a b c -> ([c] -> d) -> a b dinfixl 8combinator for converting the result of an arrow into a single element result
listA :: a b c -> a b [c]combinator for converting an arrow into a determinstic version with all results collected in a single element list
listA af = af >>. (:[])this is useful when the list of results computed by an arrow must be manipulated (e.g. sorted)
example for sorting the results of a filter
collectAndSort :: a b c -> a b c collectAndSort collect = listA collect >>> arrL sortunlistA :: a [b] bthis :: a b bthe identity arrow, alias for returnA
none :: a b cthe zero arrow, alias for zeroArrow
withDefault :: a b c -> c -> a b cconverts an arrow, that may fail, into an arrow that always succeeds
example:
withDefault none "abc"is equivalent toconstA "abc"single :: a b c -> a b cmakes a list arrow deterministic, the number of results is at most 1
definition
single f = f >>. take 1examples with strings:
runLA ( single none ) "x" == [] runLA ( single this ) "x" == ["x"] runLA ( single (constA "y" <+> this ) ) "x" == ["y"]applyA :: a b (a b c) -> a b ccompute an arrow from the input and apply the arrow to this input
definition:
(f &&& this) >>> appin a point free style, there is no way to use an argument in 2 places, this is a combinator for simulating this. first the argument is used to compute an arrow, then this new arrow is applied to the input
applyA coresponds to:
apply f x = let g = f x in g x($<) :: (c -> a b d) -> a b c -> a b dinfixl 2compute the parameter for an arrow with extra parameters from the input and apply the arrow for all parameter values to the input
a kind of "function call" for arrows, useful for joining arrows
infixl 2 ($<)definition:
g $< f = applyA (f >>> arr g)if
ffails, the whole arrow fails, e.g.g $< none == noneif
fcomputes n values andgis deterministic, the whole arrow computes n valuesexamples with simple list arrows with strings
prefixString :: String -> a String String prefixString s = arr (s++) runLA ( prefixString $< none ) "x" == [] runLA ( prefixString $< constA "y" ) "x" == ["yx"] runLA ( prefixString $< this ) "x" == ["xx"] runLA ( prefixString $< constA "y" <+> constA "z" ) "x" == ["yx","zx"] runLA ( prefixString $< constA "y" <+> this <+> constA "z" ) "x" == ["yx","xx","zx"]($<<) :: (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b dinfixl 2binary version of $<
example with simple list arrows with strings
infixString :: String -> String -> a String String infixString s1 s2 = arr (\ s -> s1 ++ s ++ s2) runLA ( infixString $<< constA "y" &&& constA "z" ) "x" = ["yxz"] runLA ( infixString $<< this &&& this ) "x" = ["xxx"] runLA ( infixString $<< constA "y" &&& (constA "z" <+> this) ) "x" = ["yxz", "yxx"]($<<<) :: (c1 -> c2 -> c3 -> a b d) -> a b (c1, (c2, c3)) -> a b dinfixl 2($<<<<) :: (c1 -> c2 -> c3 -> c4 -> a b d) -> a b (c1, (c2, (c3, c4))) -> a b dinfixl 2($<$) :: (c -> a b b) -> a b c -> a b binfixl 2compute the parameter for an arrow
fwith an extra parameter by an arrowgand apply all the results fromgsequentially to the inputinfixl 2 ($<$)typical usage:
g :: a b c g = ... f :: c -> a b b f x = ... x ... f $<$ gfcomputes the extra parameters forgfrom the input of typebandgis applied with this parameter to the input. This allows programming in a point wise style ing, which becomes neccessary, when a value is needed more than once.this combinator is useful, when transforming a single value (document) step by step, with
gfor collecting the data for all steps, andffor transforming the input step by stepif
gis deterministic (computes exactly one result),g $<$ f == g $< fholdsif
gfails,f $<$ g == thisif
gcomputes more than one result,fis applied sequentially to the input for every result fromgexamples with simple list arrows with strings
prefixString :: String -> a String String prefixString s = arr (s++) runLA ( prefixString $<$ none ) "x" == ["x"] runLA ( prefixString $<$ constA "y" ) "x" == ["yx"] runLA ( prefixString $<$ constA "y" <+> constA "z" ) "x" == ["zyx"] runLA ( prefixString $<$ constA "y" <+> this <+> constA "z" ) "x" == ["zxyx"]example with two extra parameter
g1 :: a b c1 g2 :: a b c2 f :: (c1, c2) -> a b b f (x1, x2) = ... x1 ... x2 ... f $<$ g1 &&& g2mergeA :: (a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c) -> a (a1, b1) cmerge the result pairs of an arrow with type
a a1 (b1, b2)by combining the tuple components with theoparrowexamples with simple list arrows working on strings and XmlTrees
a1 :: a String (XmlTree, XmlTree) a1 = selem "foo" [this >>> mkText] &&& selem "bar" [arr (++"0") >>> mkText] runLA (a1 >>> mergeA (<+>) >>> xshow this) "42" == ["<foo>42</foo>","<bar>420</bar>"] runLA (a1 >>> mergeA (+=) >>> xshow this) "42" == ["<foo>42<bar>420</bar></foo>"]see also: applyA, $< and
+=in classText.XML.HXT.Arrow.ArrowXmlperform :: a b c -> a b buseful only for arrows with side effects: perform applies an arrow to the input ignores the result and returns the input
example:
... >>> perform someTraceArrow >>> ...catA :: [a b c] -> a b cgeneralization of arrow combinator <+>
definition:
catA = foldl (<+>) noneseqA :: [a b b] -> a b bgeneralization of arrow combinator >>>
definition:
seqA = foldl (>>>) this