Created
October 23, 2019 02:54
-
-
Save lumie1337/06ae42e03bdc9567911a692964c2ea6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addName counter names name = do | |
i <- readTVar counter | |
ns <- readTVar names | |
orElse addName' $ return () | |
where | |
addName' = do | |
guard $ any ((== name) . snd) ns | |
writeTVar names ((i, name) : ns) | |
writeTVar counter (i + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment