Need help to understand the usage of `liftBase`

bmk

I am currently reading through (for self studying purpose) the source code of the Bryan O'Sullivan's popular pool library.

And I have a question in the function takeResource, which I would like to ask the Haskell experts here. The function is defined as:

takeResource :: Pool a -> IO (a, LocalPool a)
takeResource pool@Pool{..} = do
  local@LocalPool{..} <- getLocalPool pool
  resource <- liftBase . join . atomically $ do
  ents <- readTVar entries
  case ents of
    (Entry{..}:es) -> writeTVar entries es >> return (return entry)
    [] -> do
      used <- readTVar inUse
      when (used == maxResources) retry
      writeTVar inUse $! used + 1
      return $
        create `onException` atomically (modifyTVar_ inUse (subtract 1))
  return (resource, local)

The line I am having problem with is

...
resource <- liftBase . join . atomically $ do
...

Why is here the usage of liftBase necessary? Can we also write instead

...
resource <- join . atomically $ do
...

The compiler accepts both versions. Am I missing here something trivial or why is liftBase here necessary?

Thank you in advance for the tips!

Michael Snoyman

I think I'm responsible for that. No, there's no purpose for it to be there, it can be removed. I think it was necessary before some refactoring. You could send a pull request and be part of an awesome library :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Need help to understand code

From Dev

Need help to understand this code

From Dev

Need help to understand LISP

From Dev

Gradle: need help to understand

From Java

Need to understand the usage of SemaphoreSlim

From Dev

Not able to run meteor in cloud ide, need help to understand meteor memory usage

From Dev

Need help to understand LPeg and PEGs

From Dev

Need help to understand code in python

From Dev

Need some help to understand recursion

From Dev

Need Help to understand the piece of code

From Dev

Need help to understand LPeg and PEGs

From Dev

Need help to understand code in python

From Dev

Need help to understand SQL query

From Dev

Need help to understand while loop

From Dev

Need help to understand the purpose of a following class

From Dev

Perl print %hash - need some help to understand this

From Dev

Need help to understand the code with pointers and arrays in c

From Dev

lua script :need help to understand the scope of an variable

From Dev

Need help to understand a sentence in DSE Cassandra documentation -

From Dev

Need help to understand merge conflict example

From Dev

c# Need help to understand this code

From Dev

Need help to understand kernel debugging error

From Dev

Need help to understand deserialization with ArrayList in Java

From Dev

I need help to understand cv::mixChannels

From Dev

PHP - Need help to understand injected code

From Dev

Need Help to Understand Regular Expression Immediately

From Dev

Need help to understand the purpose of a following class

From Dev

Advanced php formatting need help understand layout

From Dev

Need help understanding *args + reduce usage in Python

Related Related

HotTag

Archive