git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
39 lines 862 B history raw
1module Snapshot.EffectRefs01 where
3import Prelude
5import Effect (Effect)
6import Effect.Ref (Ref)
7import Effect.Ref as Ref
9test1 :: Effect (Ref Int)
10test1 = Ref.new 42
12test2 :: forall a. (Int -> a) -> Effect (Ref a)
13test2 g = Ref.new (g 42)
15test3 :: forall a. Ref a -> Effect a
16test3 r = Ref.read r
18test4 :: forall a b. (a -> Ref b) -> a -> Effect b
19test4 g r = Ref.read (g r)
21test5 :: Ref Int -> Effect Unit
22test5 r = Ref.write 42 r
24test6 :: forall a. (Int -> a) -> Ref a -> Effect Unit
25test6 g r = Ref.write (g 42) r
27test7 :: forall a. (a -> a) -> Ref a -> Effect a
28test7 g r= Ref.modify g r
30test8 :: forall a. (forall b. b -> b) -> Ref a -> Effect a
31test8 g r = Ref.modify (g g) r
33test9 :: (Int -> Int) -> Effect Int
34test9 g = do
35 ref <- Ref.new (g 42)
36 prev <- Ref.read ref
37 Ref.write (prev + 1) ref
38 _ <- Ref.modify (add 1) ref
39 Ref.read ref