{-# 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