git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
31 lines 695 B history raw
1module Snapshot.EffectRefs02 where
3import Prelude
5import Data.Tuple (Tuple(..))
6import Effect (Effect, whileE)
7import Effect.Ref (Ref)
8import Effect.Ref as Ref
10test1 :: Int -> Effect Int
11test1 hi = do
12 count <- Ref.new 0
13 continue <- Ref.new true
14 whileE (Ref.read continue) do
15 n <- Ref.read count
16 void $
17 if n < hi then
18 Ref.write (n + 1) count
19 else
20 Ref.write false continue
21 Ref.read count
23test2 :: Effect (Int -> Effect Unit)
24test2 = do
25 count <- Ref.new 0
26 pure \n -> void $ Ref.modify (_ + n) count
28test3 :: Effect (Tuple (Ref Int) (Int -> Effect Unit))
29test3 = do
30 count <- Ref.new 0
31 pure $ Tuple count \n -> void $ Ref.modify (_ + n) count