I am new to haskell programming. I would like an example code of how I can quit a main program by entering a command (for example QUIT)and go back to the default Prelude> screen. I am using the GHC 7.8.3 interpreter. Please also mention which which module(s) I would need to import if any. I have been searching all over and trying different things but nothing seems to work. Really want to know how to do this asap. Thank you very much in advance
2
There are 2 best solutions below
0
icktoofay
On
You can use one of the functions from the System.Exit module. The simplest use would probably be something like this:
import System.Exit (exitSuccess)
main = exitSuccess
Of course, it is not of great utility in this example, but you can place it anywhere an IO () can be used, and it will terminate the program. In GHCi, the exception it throws will be caught, and you will return to the Prelude> prompt after an *** Exception: ExitSuccess line.
Related Questions in HASKELL
- Typeclass projections as inheritance
- How to generate all possible matrices given a number n in Haskell
- Is there a way to get `cabal` to detect changes to non-Haskell source files?
- How to have fixed options using Option.Applicative in haskell?
- How can I create a thread in Haskell that will restart if it gets killed due to any reason?
- Automatic Jacobian matrix in Haskell
- Haskell writing to named pipe unexpectedly fails with `openFile: does not exist (No such device or address)`
- Why does Enum require to implement toEnum and fromEnum, if that's not enough for types larger than Int?
- Non-exhaustive patterns in function compress
- How to get terms names of GADT in Template Haskell?
- Implementing eval() function with Happy parser generator
- How to count the occurences of every element in a list in Haskell fast?
- In Haskell, what does `Con Int` mean?
- Extract a Maybe from a heterogeneous collection
- Haskell, Stack, importing module shows error "Module not found"
Related Questions in EXIT
- How to close an express and a websocket server on the git bash terminal close on Windows
- Problems with docker nodejs app exit code 137
- Why does this Python script hang? async-await? Django-ORM?
- python does not recognize "quit()"
- Exiting a timer macro before calling it again
- exit() status does not act accordingly
- C++ exit(1) causes IO loss?
- Using Python and YOLOv8 for simple bounding box creation. Program won't stop and can't be aborted
- Framer-motion AnimatePresence - apply dynamic color change before fade begins
- I tried to do exit the app on second tap using Popscope but it didn't work on the way I expected, It didn't even exit
- Are you allowed to have fork as a for condition?
- framer motion exist transition is not working
- Why does getattr() exit a program when it raises an exception inside a try statement?
- Why pressing Ctrl + C to interrupt a node js server application doesn't close previous opened ports?
- How do I exit GNU APL?
Related Questions in TERMINATE
- Codespace terminates my code within seconds?
- Understand what really happens when calling a throwing function in a noexcept function
- Does this criteria prove that Y calls X in infinite recursion?
- How can I determine whether a user is watching YouTube Shorts or using the regular YouTube app within my Flutter application?
- Powerbuilder Response window hangs then App closes - Any ideas?
- How to make sure the process signalled to terminate using TerminateProcess WinAPI is actually terminated?
- Elegant loop exit using input() with multithreading
- Running a custom termination of a process in python multiprocessing
- How to terminate processes in a specific order?
- How to properly terminate a process that is running in the background via subprocess?
- Cannot terminate or kill subprocess after building .exe with pyinstaller
- Is there any keyword that will terminate or stop the simulation when the output reaches a specific value in open modelica?
- Which function is invoked on click of notification while flutter android app is in terminated state, background notification click FCM
- What should i write inside JOptionPane.YES_NO_OPTION
- IPOPT Options Not Settable in Visual Studio 2022 Release Configuration
Related Questions in EXIT-CODE
- The preLaunchTask 'C/C++:gcc.exe build active file' terminated with exit code -1 Error
- It is possible to detect a crash of the Java VM on its exit code?
- Process.Start finished with exit code 1
- Clion Process finished with exit code -1073741819 (0xC0000005) problem
- On VScode, why does my code immediately execute a exit code=1?
- "The terminal process "/usr/local/bin/bash '-l'" terminated with exit code: 1."
- java Process returns exit code 35 on first iteration only
- Python program works with test cases but PyTest fails. How can I understand the issue?
- How we can define Enter and Exit block to conenct the main flowchart in any logic?
- Is there a standard set of exit code numbers for C/C++?
- wicked_pdf libssl.so.1.1 cannot open shared object file, no such file or directory
- Is there supposed to be "iptables-restore < /etc/iptables.ipv4.nat" before an exit 0 statement?
- Why does adb return zero exit status in case of "failed to connect"?
- Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) - How can I solve this issue with my code below?
- App compatibility issues in Xcode15 bitrise build
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This SO answer contains a basic read-execute loop: https://stackoverflow.com/a/27094682/866915
When you see the
Prelude>prompt you are operating within the programghci, and you will get back to that prompt when the function you've called returns.An abbreviated example: