-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
[original issue 94 by @Icelandjack]
Is it possible to weaken the constraints of evalStateT and execStateT from Monad to Functor?
evalStateT :: Functor f => StateT s f a -> s -> f a
evalStateT m s = fst <$> runStateT m s
execStateT :: Functor f => StateT s f a -> s -> f s
execStateT m s = snd <$> runStateT m sThis came up translating withIndex (https://github.com/mstksg/inCode/blob/e1f80a3dfd83eaa2b817dc922fd7f331cd1ece8a/app-purescript/Entry.purs#L279) to Haskell
withIndex
:: forall s t a b f. Functor f -- Monad f
=> ((a -> StateT Int f b) -> (s -> StateT Int f t))
-> (Int -> a -> f b) -> (s -> f t)
withIndex lens f = (`myEvalStateT` 0) . lens f'
where
f' :: a -> StateT Int f b
f' y = StateT \i -> (\z -> (z, i+1)) <$> f i yReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels