Relaxed type signature of asks function

It's previous type signature:

  asks :: (e -> a) -> Eff '[Reader e] a

Was very restrictive, therefore, its usage was limited to very few
effect stacks. New type signature:

  asks :: Member (Reader e) effs => (e -> a) -> Eff effs a

Is much more liberal, and allows us to use `asks` in all the places we
would have to use something like `f <$> ask`.

Resolves #7
This commit is contained in:
Peter Trsko 2017-01-30 16:24:45 +01:00 committed by Peter Trško
parent 766e4e03ab
commit 7c1c7437e9

View File

@ -63,16 +63,16 @@ ask = send Reader
-- | Request a value of the environment, and apply as selector\/projection -- | Request a value of the environment, and apply as selector\/projection
-- function to it. -- function to it.
asks asks
:: (e -> a) :: Member (Reader e) effs
=> (e -> a)
-- ^ The selector\/projection function to be applied to the environment. -- ^ The selector\/projection function to be applied to the environment.
-> Eff '[Reader e] a -> Eff effs a
asks f = f <$> ask asks f = f <$> ask
-- | Handler for 'Reader' effects. -- | Handler for 'Reader' effects.
runReader :: Eff (Reader e ': effs) a -> e -> Eff effs a runReader :: Eff (Reader e ': effs) a -> e -> Eff effs a
runReader m e = handleRelay pure (\Reader k -> k e) m runReader m e = handleRelay pure (\Reader k -> k e) m
-- | Locally rebind the value in the dynamic environment. -- | Locally rebind the value in the dynamic environment.
-- --
-- This function is like a relay; it is both an admin for 'Reader' requests, -- This function is like a relay; it is both an admin for 'Reader' requests,