| Introduction | Arrow syntax | Bibliography | Downloads |
|---|---|---|---|
|
Hughes's original formulation of arrows used a point-free style, which is convenient for calculating general properties, but cumbersome for specific definitions. [Pat01] proposes to extend Haskell so that arrows are almost as convenient to describe as monadic computations. The new forms are defined by translation back to standard Haskell. Here's a simple example to illustrate the notation:
addA :: Arrow a => a b Int -> a b Int -> a b Int
addA f g = proc x -> do
y <- f -< x
z <- g -< x
returnA -< y + z
![]() First, note that there are two new keywords:
If you think of proc as lambda and -< as application, the above looks very much like the do-notation for monads. Bear in mind however that behind the notation lie the more general arrows, as can be seen in the Haskell translation:
addA f g = arr (\ x -> (x, x)) >>>
first f >>> arr (\ (y, x) -> (x, y)) >>>
first g >>> arr (\ (z, y) -> y + z)
![]() Of course in this particular case a much more concise translation is possible:
addA f g = f &&& g >>> arr (\ (y, z) -> y + z)
![]() but the preprocessor isn't that smart. Some more examples:
The last two examples use more fancy definitions from the experimental arrow library (see the download page). Here are the translation rules used. (The old version was a little lighter, but less powerful.) ImplementationTwo implementations are available:
Bugs and LimitationsGeneral limitations:
The rest relate to the preprocessor, not the GHC implementation.
|
|||
| Introduction | Arrow syntax | Bibliography | Downloads |
Ross Paterson