on 294fdfd help sign in
elk/compiler/Model/Guid.hs
17 lines 452 B history raw
1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2module Guid (guid, run, runAt, GuidCounter) where
4import Control.Monad.State (evalState, State, get, put)
6-- Wrapper around State monad.
7newtype GuidCounter a = GC { runGC :: State Int a }
8 deriving (Monad)
10-- Get the next GUID, incrementing the counter.
11guid :: GuidCounter Int
12guid = GC $ do n <- get
13 put (n + 1)
14 return n
16run = runAt 0
17runAt n x = evalState (runGC x) n