module AERN2.Utils.Arrows
(
mapA, mapWithIndexA
, CanSwitchArrow(..)
)
where
import MixedTypesNumPrelude
import Control.Arrow
class CanSwitchArrow to1 to2 where
switchArrow :: (a `to1` b) -> (a `to2` b)
instance (Arrow to) => CanSwitchArrow (->) to where
switchArrow = arr
mapA :: (ArrowChoice to) => (t1 `to` t2) -> ([t1] `to` [t2])
mapA fA =
proc list -> do
case list of
[] -> returnA -< []
(x : xs) -> do
y <- fA -< x
ys <-mapA fA -< xs
returnA -< y : ys
mapWithIndexA :: (ArrowChoice to) => (Integer -> t1 `to` t2) -> ([t1] `to` [t2])
mapWithIndexA fA = aux 0
where
aux i =
proc list -> do
case list of
[] -> returnA -< []
(x : xs) -> do
y <- fA i -< x
ys <- aux (i+1) -< xs
returnA -< y : ys