summaryrefslogtreecommitdiff
path: root/src/Util/IdGen.hs
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2025-01-20 16:51:22 +0100
committerTom Smeding <t.j.smeding@uu.nl>2025-01-20 16:51:22 +0100
commit0bdc36d221703e5a2347d3d136d676a86bdb1b6a (patch)
tree2ebecd0669573a2dd9634ea43753e91bcce4181c /src/Util/IdGen.hs
parent27e5422c541623fbee36f2eedf37bb3d2ca3d14c (diff)
WIP identity analysis
Diffstat (limited to 'src/Util/IdGen.hs')
-rw-r--r--src/Util/IdGen.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Util/IdGen.hs b/src/Util/IdGen.hs
new file mode 100644
index 0000000..fcfb6e7
--- /dev/null
+++ b/src/Util/IdGen.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+module Util.IdGen where
+
+import Control.Monad.Trans.State.Strict
+
+
+newtype IdGen a = IdGen (State Int a)
+ deriving newtype (Functor, Applicative, Monad)
+
+genId :: IdGen Int
+genId = IdGen (state (\i -> (i, i + 1)))
+
+runIdGen :: Int -> IdGen a -> a
+runIdGen start (IdGen m) = evalState m start
+
+runIdGen' :: Int -> IdGen a -> (a, Int)
+runIdGen' start (IdGen m) = runState m start