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

Add :quit repl command #719

Merged
merged 4 commits into from
Nov 29, 2018
Merged

Add :quit repl command #719

merged 4 commits into from
Nov 29, 2018

Conversation

kedashoe
Copy link
Contributor

For #707

Not sure what the "best" way to quit is, throw Interrupt seems a bit odd to me but I couldn't figure out a better way..

Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kedashoe: Your solution is actually just fine. The Interrupt exception is how repline expects to signal the end of the REPL eval loop. Just one minor comment

cmdQuit :: ( MonadIO m, MonadState Env m ) => [String] -> m ()
cmdQuit _ = do
liftIO (putStrLn "Goodbye.")
throw Interrupt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You usually want to prefer throwIO instead of throw since throw can accidentally be triggered by evaluation whereas throwIO is evaluation-safe. Or in other words:

throw x `seq` () = throw x

throwIO x `seq` () = ()
Suggested change
throw Interrupt
liftIO (throwIO Interrupt)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah so technically it is possible it could throw without putStrLning? Updated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! The repline loop has logic that checks if the last command was non-empty when an Interrupt was thrown. If the command is empty then it says Goodbye. and if it was non-empty then it says nothing. This is why you had to insert an explicit Goodbye. to match the behavior because :quit was a non-empty command.

@Gabriella439 Gabriella439 merged commit bafab77 into dhall-lang:master Nov 29, 2018
@Gabriella439
Copy link
Collaborator

Thank you for contributing this! 🙂

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

Successfully merging this pull request may close these issues.

2 participants