[Move a few deckchairs around. No significant content changes. Bryan O'Sullivan **20070701174336] { hunk ./en/ch02-starting.xml 202 + + + + Basic interaction: using ghci as a calculator + + Where some people might run a calculator program, I often + drop into &ghci; to perform simple calculations. Using it this + way serves as a good way to become familiar with &ghci; itself, + and with the basics of Haskell expressions. + hunk ./en/ch02-starting.xml 338 - a standard module named - The Prelude module - is most often referred to simply as the - prelude (or occasionally, as the - standard prelude). - + (The Prelude module + is often referred to as the standard prelude, + because its contents are defined by the Haskell 98 standard. + Sometimes, it's simply shortened to the + prelude.) hunk ./en/ch02-starting.xml 381 - - Don't sweat the error messages - - Remember the point we made earlier about explicit - parentheses often being good? Here's an example of that idea - in action, except here the parentheses are - necessary, not merely a good idea. - - &basics.ghci:denom.bad; - - Look at that scary error message! We're new to Haskell! - How are we supposed to interpret all of that? The first thing - we must do is take a deep breath and not worry about the - details. - - If we step back and gloss over the error message, we can - see that &ghci; is displaying for us the expression that it - had trouble with. And it has helpfully added parentheses back - into the expression, only look! They're in the wrong - places - - This isn't the fault of &ghci;. It just happens that the - (%) and (*) - operators have the same precedences, so &ghci; parses the - expession from left to right. As a result, it tries to - construct a rational from another rational and an integer, - instead of from a pair of integers. (If - (%) had a higher precedence than - (*), the expression would be parsed the - way we might have hoped.) - - All we have to do to correct this problem is add some - explicit parentheses to say what we really mean. - - &basics.ghci:denom.good; - - - The important lesson here is one that we'll be repeating - over and over throughout the early sections of this book. If - you run into problems, don't panic. You - do not need to understand every little detail of what's - going on. Early on, all you have to do is figure out enough - to make progress through a problem. Complete understanding - can wait. - - - hunk ./en/ch02-starting.xml 434 + + + + Don't sweat those error messages + + Remember the point we made earlier about explicit + parentheses often being good? Here's an example of that idea in + action, except here the parentheses are + necessary, not merely a good idea. + + &basics.ghci:denom.bad; + + Look at that error message; it's detailed, and mentions a + lot of concepts we haven't covered yet. We're new to Haskell! + How are we supposed to interpret all of that? The first thing + we must do is take a deep breath and not worry about the + details. + + If we step back and gloss over the error message, we can see + that &ghci; is displaying for us the expression that it had + trouble with. And it has helpfully added parentheses back into + the expression, only look! They're in the wrong + places + + This isn't the fault of &ghci;. It just happens that the + (%) and (*) operators + have the same precedences, so &ghci; parses the expession from + left to right. As a result, it tries to construct a rational + from another rational and an integer, instead of from a pair of + integers. (If (%) had a higher precedence + than (*), the expression would be parsed + the way we might have hoped.) + + All we have to do to correct this problem is add some + explicit parentheses to say what we really mean. + + &basics.ghci:denom.good; + + + The important lesson here is one that we'll be repeating + over and over throughout the early sections of this book. If + you run into problems, don't panic. You + do not need to understand every little detail of what's going + on. Early on, all you have to do is figure out enough to make + progress through a problem. You don't need instantaneous + complete understanding, so don't worry if you don't have + it. + + }