You need a “unique supply”. The usual way to do this in Haskell is by threading a counter through the State monad, which automates the plumbing problem you describe.
More Related Contents:
- Haskell GHC: what is the time complexity of a pattern match with N constructors?
- `String’ is applied to too many type arguments
- How do I define Lisp’s apply in Haskell?
- Operating on a return from a Maybe that contains “Just”
- Is there a Haskell idiom for updating a nested data structure?
- What’s so bad about Lazy I/O?
- Positive integer type
- Explicitly import instances
- How to compare two functions for equivalence, as in (λx.2*x) == (λx.x+x)?
- Why do 3 and x (which was assigned 3) have different inferred types in Haskell? [duplicate]
- How do I use fix, and how does it work?
- List of different types?
- What is Levity polymorphism
- How to infer the type of an expression manually
- Understanding the Haskell as-pattern
- Haskell: How to create most generic function possible that applies a function to tuple items
- Concrete example showing that monads are not closed under composition (with proof)?
- How to use (->) instances of Monad and confusion about (->)
- Why can a Num act like a Fractional?
- Composing function composition: How does (.).(.) work?
- Why doesn’t TypeSynonymInstances allow partially applied type synonyms to be used in instance heads?
- What’s the status of multicore programming in Haskell?
- Tools for analyzing performance of a Haskell program
- How does foldr work?
- How to catch a no parse exception from the read function in Haskell?
- Is there a list of GHC extensions that are considered ‘safe’?
- Haskell Constraint is no smaller than the instance head
- Can I match a data constructor wildcard in Haskell?
- Is there, in Haskell, something similar to sub-guards?
- What is the Comonad typeclass in Haskell?