Created
September 13, 2023 18:53
-
-
Save graninas/d3f4e001f549020ac9fb60ca50482957 to your computer and use it in GitHub Desktop.
Some thoughts on merging Church Free and State monad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Option 1: State as an eDSL | |
data StateMethod s next | |
= Put s (() -> next) | |
| Get (s -> next) | |
instance Functor (StateMethod s) where | |
fmap f (Put st next) = Put st (f . next) | |
fmap f (Get next) = Get (f . next) | |
type FreePoweredState st a = F (StateMethod st) a | |
put :: s -> FreePoweredState s () | |
put st = liftF (Put st id) | |
get :: FreePoweredState s s | |
get = liftF (Get id) | |
-- Option 2: State as a part of Church Free (may be incorrect): | |
newtype StateMergedChurch s f a = MyChurch | |
{ runMyChurch | |
:: forall r | |
. (s -> a -> (s, r)) -- Pure case | |
-> (s -> f r -> (s, r)) -- Continuation case | |
-> s -- initial state | |
-> (s, r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment