-
-
Notifications
You must be signed in to change notification settings - Fork 828
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
[error] Function Definition in GHCi on Linux 5.8 #59
Comments
Hi @nasirhm! When the section describes top-level function definitions and type-signatures, it talks about writing them inside a file, not inside REPL. GHCi can parse only one line at a time by default. But a function definition requires two lines: a type signature and a function body. That's why creating new functions in GHCi is awkward, and the course assumes that you will implement new functions inside a module, and then load the module in GHCi. If you start fresh GHCi, and try to insert this string, you will get the following error: Prelude> roundSubtract :: Double -> Int -> Int
<interactive>:8:1: error:
Variable not in scope: roundSubtract :: Double -> Int -> Int What you probably did, is that you've copied the implementation of Let me know if clarifies some things, or whether you need more help 🙂 |
Hello guys, maybe its possible to write function definition with ";" inline. |
@vasylzhmurko Yes, you can write a function type signature and its implementation in a single line by separating type signature and body with a semicolon You can also use special GHCi commands Defining functions in one-line in GHCi sometimes useful, but it's not how you usually write them in the module. Also, once you start having more complex bodies (guards, nested if-then-else expressions, etc.), writing everything in a single line becomes very awkward. I'm closing this issue, as the question seems to be answered 🙂 Let us know if you have other questions! |
Nice catch, Will keep it in mind for the next examples 👍 Thank You for answering and information @vasylzhmurko and @chshersh :) |
Hey Awesome people, First of all thank you very much for the amazing idea of learning Haskell in 4 PRs with Hacktoberfest (I
absolutely love the Idea ❤️ )
I'm trying to define a function in Glassgow Haskell Compiler's REPL by executing the following line :
and It results in the following error:
On the tutorial, In
Chapter1.hs
, on line 358, It asks to do it.CC: @chshersh @vrom911
The text was updated successfully, but these errors were encountered: