-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.hs
50 lines (42 loc) · 1.37 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
module Main where
import Control.Effect (type (<:), type (<<:))
import Control.Effect.ExtensibleChurch (runEff)
import Control.Effect.Hefty (interpretRecH)
import Control.Effect.Interpreter.Heftia.Writer (elabWriterPost, elabWriterPre, runTell)
import Control.Monad.IO.Class (liftIO)
import Data.Effect.Writer (Tell, WriterH, censor, tell)
hello :: (Tell String <: m, Monad m) => m ()
hello = do
tell "Hello"
tell " world!"
censorHello :: (Tell String <: m, WriterH String <<: m, Monad m) => m ()
censorHello =
censor
( \s ->
if s == "Hello"
then "Goodbye"
else
if s == "Hello world!"
then "Hello world!!"
else s
)
hello
main :: IO ()
main = runEff do
(sPre, _) <-
runTell
. interpretRecH (elabWriterPre @String)
$ censorHello
(sPost, _) <-
runTell
. interpretRecH (elabWriterPost @String)
$ censorHello
liftIO $ putStrLn $ "Pre-applying: " <> sPre
liftIO $ putStrLn $ "Post-applying: " <> sPost
{-
Pre-applying: Goodbye world!
Post-applying: Hello world!!
-}