1. Jean-Marie Gaillourdet
  2. global-variables

Commits

Jean-Marie Gaillourdet  committed 93367c4

added examples

  • Participants
  • Parent commits dc98d2f
  • Branches default

Comments (0)

Files changed (3)

File examples/multimodule/Main.hs

View file
+module Main where
+
+import Data.IORef
+import Data.Global
+
+import Module1
+import Module2
+
+main :: IO ()
+main = do 
+    increaseBy2
+    tripple
+    increaseBy2
+    tripple
+    let ref = declareIORef "my-global-var" 17 :: IORef Int
+    print =<< readIORef ref

File examples/multimodule/Module1.hs

View file
+module Module1 (
+    increaseBy2
+)where
+
+import Data.Global
+import Data.IORef
+
+someVar :: IORef Int
+someVar = declareIORef "my-global-var" 0
+
+increaseBy2 :: IO ()
+increaseBy2 = atomicModifyIORef someVar inc2
+  where
+    inc2 x = (2+x, ())

File examples/multimodule/Module2.hs

View file
+module Module2 (
+    tripple
+) where
+
+
+import Data.Global
+import Data.IORef
+
+someVar :: IORef Int
+someVar = declareIORef "my-global-var" 0
+
+tripple :: IO ()
+tripple = atomicModifyIORef someVar tripple'
+  where
+    tripple' x = (x*3, ())