Just got started with Arrows yesterday. As an exercise, I decided to try to build a "Reader Arrow" analogous to Control.Monad.Reader.Reader
. I've called it EA
("Environment Arrow"). Question follows after code.
import Prelude hiding ((.), id)
import Control.Category
import Control.Arrow
import qualified Data.Bifunctor as BiF
newtype EA r a b = EA { runEA :: r -> a -> b }
instance Arrow (EA r) where
arr f = EA $ const f
first (EA f) = EA $ BiF.first . f
second (EA f) = EA $ BiF.second . f
instance Category (EA r) where
id = arr id
(EA b) . (EA a) = EA $ \r -> b r . a r
ask :: EA r a r
ask = EA const
test :: EA Int Int Int
test = proc i -> do
f <- ask -< i -- How can I build an "ask" that doesn't need a parameter?
returnA -< f
How can I build ask
so that it works with proc
notation but does not need a parameter? In other words, I want to say f <- ask
and not f <- ask -< i
, since the parameter is never used.
It can't be done. f <- ask
isn't even valid syntax in arrow notation. Every arrow must be "applied" to some argument in a proc
block.