-
Notifications
You must be signed in to change notification settings - Fork 214
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
Conversation
There was a problem hiding this 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
dhall/src/Dhall/Repl.hs
Outdated
cmdQuit :: ( MonadIO m, MonadState Env m ) => [String] -> m () | ||
cmdQuit _ = do | ||
liftIO (putStrLn "Goodbye.") | ||
throw Interrupt |
There was a problem hiding this comment.
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` () = ()
throw Interrupt | |
liftIO (throwIO Interrupt) |
There was a problem hiding this comment.
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 putStrLn
ing? Updated.
There was a problem hiding this comment.
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.
Thank you for contributing this! 🙂 |
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..