Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with the logging API #55

Open
harendra-kumar opened this issue May 13, 2017 · 2 comments
Open

Issues with the logging API #55

harendra-kumar opened this issue May 13, 2017 · 2 comments

Comments

@harendra-kumar
Copy link
Contributor

With the current design of the logging primitives, it is possible to easily run into inconsistent behavior. For example:

main = keep $ restore $ do
     r <- choose [1..5 :: Int]
     logged $ liftIO $ print ("A",r)
     suspend ()
     liftIO $ print ("B",r)

Here, the programmer forgot to add logged to the choose primitive. This results in an incorrect output. Another example, if we use suspend without logging, the program always suspends:

main = keep $ do
     r <- choose [1..5 :: Int]
     liftIO $ print ("A",r)
     suspend ()
     liftIO $ print ("B",r)

Instead we should either throw an error or ignore the suspend since we are not logging.

A potential solution to these problems is to design the API such that we use the logged primitive one level above the suspend. If the parent is logged then logging is inherited by all the child computations and we can suspend a child. Since we know the logged/not logged state we can change the behavior of suspend based on that. Also, the logged primitive itself can do the job of restore as well. The code will look like:

main = keep $ logged $ do
     r <- choose [1..5 :: Int]
     liftIO $ print ("A",r)
     suspend ()
     liftIO $ print ("B",r)

I have not thought much about it, so I am not sure if this solution has any inherent problems.

@agocorona
Copy link
Collaborator

agocorona commented May 18, 2017 via email

@harendra-kumar
Copy link
Contributor Author

Yeah, I figured that when I later looked at the Cloud monad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants