Talk:Haskell/Next steps

First of all, I'm just a reader learning Haskell, but I do have previous experience with other languages. In reference to the fix me, I do not see how lists could be introduced without some mentioning types, as it appears you need to designate the type when creating a list. For this reason, it might be better to either present types earlier, or present lists later. 70.105.36.254 16:01, 9 July 2006 (UTC)


 * Please take a look at Haskell/List basics and let us know what you think. Thanks, -- Kowey 23:58, 10 July 2006 (UTC)

Which Problem ?
you write :

Let Bindings

Often we wish to provide local declarations for use in our functions. For instance, if you remember back to your grade school mathematics courses, the following equation is used to find the roots (zeros) of a polynomial of the form ax2 + bx + c = 0: x = (-b \pm \sqrt{b^2-4ac}) / 2a. We could write the following function to compute the two values of x:

roots a b c = ((-b + sqrt(b*b - 4*a*c)) / (2*a),    (-b - sqrt(b*b - 4*a*c)) / (2*a))

To remedy this problem ...

Which problem ? The returning of 2 Values ?


 * I have added some extra text to (hopefully) make it a little clearer. Thanks! The text:
 * Notice that our definition here has a bit of redundancy. It is not quite as nice as the mathematical definition because we have needlessly repeated the code for sqrt(b*b - 4*a*c). To remedy this problem, Haskell allows for local bindings -- Kowey 09:52, 13 February 2007 (UTC)

Compiling With GHC
"GHC can also be used as a compiler. That is, you could use GHC to convert your Haskell files into a program that can then be run without running the interpreter. See the documentation for details."

I assume that GHC best practices will be covered in later chapters, but a link the correct section of the GHC documentation (perhaps intended for beginners) would be more useful than "See the documentation...". Abdelazer 23:59, 31 May 2007 (UTC)

In order to compile your .hs file into an executable program, do the following (in Windows):
 * I believe it will be extremely useful for absolute n00bers like me (who literally spent hours trying to make sense of the compiling instructions), the following piece of information:
 * 1) Open the cmd prompt and navigate to the directory where your file is: cd C:\test\haskell
 * 2) Compile: C:\ghc\ghc-6.8.2\bin\ghc --make filename.hs

Actually it also works with ghc --make filename (without the .hs extention) ; ghc --make filename.hs -o filename.exe, etc.

Distinguish Between GHCi Commands and Haskell?
"Now change into the directory where you saved your file, open up ghci, and use :load (or :l for short):"

Perhaps a Note could be added that would make it clear the distinction between Haskell syntax and GHCi commands (prefixed by ':')? Something like this:

Abdelazer 00:09, 1 June 2007 (UTC)

Magic
Here, the order is important. If we had put the last line first, it would have matched every argument, and f would return -1, regardless of its argument (most compilers will warn you about this, though, saying something about overlapping patterns).

The  (underscore) character has not been defined for pattern matching yet. Text should be added to describe use of  as the wildcard character. Something like this:

"In this example, the order is important because serves as a wildcard character for pattern matching (it matches everything). If we had put the last line first,   would have matched every argument, and the function   would always return $-1$, regardless of its argument. Most compilers will warn you about this, though, saying something about overlapping patterns." Abdelazer 00:25, 1 June 2007 (UTC)

Prelude Pointer Too Soon?
"It would probably be wise to take a little time-out to look at some of the functions that are defined in the Prelude. Undoubtedly, at some point, you will accidentally rewrite some already-existing function (I've done it more times than I can count), but if we can keep this to a minimum, that would save a lot of time."

The reader has not been introduced to the term "Prelude" yet, so some introductory text would be useful (perhaps a clarification of: "The Haskell Prelude contains predefined classes, types, and functions that are implicitly imported into every Haskell program.". Additionally, the Prelude should be linked rather than just referenced in plain text. Finally, I think this whole Prelude discussion should probably be moved to later in the text, as the Prelude syntax is too complex for a beginner at this stage.

I also thought that observation was a bit weirdly placed, so I rephrased it and included the link. --Duplode (talk) 03:21, 29 April 2010 (UTC)

math tags
I think that tags are overused here.

Putting them on plain numbers is a bit too much, for example in the case section. --Amir E. Aharoni 20:11, 8 June 2007 (UTC)

Boy, I agree! Actually, I'm one of those people that will only put math tags on displayed material, never (almost) on inline material. If it needs a math tag, then it should probably be displayed. &mdash;Toby Bartels (talk) 15:18, 22 October 2008 (UTC)

Test module?
When the if statement is introduced, the prompt mysteriously changes to Test> and there is a statement like

"If Test is the current module..."

I assume that the concept of module in Haskell is something which will be coming up, but right now it's mysterious, at least to me.


 * Thanks for pointing that out. Such are the dangers of careless remixing (the section was lifted from Haskell/YAHT, which briefly mentions modules in the right place.  I have taken out all references to modules -- Kowey 09:02, 30 June 2007 (UTC)

Does order matter?
In Section 1.3, you say that order doesn't matter. Then in Section 2.3, you say that order is important. Which is it? (I fear that Section 2.3 is correct, and wonder what Section 1.3 is really trying to say.) &mdash;Toby Bartels (talk) 15:24, 22 October 2008 (UTC)


 * Order doesn't matter for declarations (i.e. first  then   or the other way round) but it does matter for pattern matching (i.e. first the case   and then   or the other way round). That seems to be what section 1.3 and 2.3 want to say.
 * -- apfe&lambda;mus 08:35, 23 October 2008 (UTC)


 * Thanks Apfelmus, that sounds plausible (especially now that I've read further about pattern matching). I hope that somebody knows for sure and will update (at least) Section 1.3. &mdash;Toby Bartels (talk) 01:48, 25 October 2008 (UTC)

Hehe
I just finished watching the A Taste of Haskell talk for oscon 07 and decided to check out the wikibook

I saw this line
 * The interpreter is indeed a useful tool

And grinned. That's Simon Peyton-Jones's voice, I recognize it! Maybe? The diff's username doesn't look promising 96.239.136.119 (talk) 01:38, 20 September 2009 (UTC)


 * Haha, I don't think SPJ is editing the wikibook, but he has written other tutorials like Tackling the Awkward Squad : monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell or A Tutorial on Parallel and Concurrent Programming in Haskell.
 * -- apfe&lambda;mus 07:37, 20 September 2009 (UTC)

Pattern matching is mentioned too soon again
In the guidelines for contributors, it seemed clear that concepts shouldn't be mentioned before they are explained. Why do we have pattern matching here, then? The case statement can wait until then. --Digichoron (discuss • contribs) 20:06, 4 April 2011 (UTC)

Nested if constructs?
This book is intended for readers of all levels of programming background, and they might not know about nested if constructs yet, or when they are used. However, the section on the case construct mentions that the case construct solves the problems that nested if constructs can solve more easily. Even if the section on the case construct is not going to be moved (see the last section, which I added), nested ifs should be shown first. --Digichoron (discuss • contribs) 00:04, 5 April 2011 (UTC)

On the Indentation section
There is a page in a later part of the book that explains this more thoroughly that would be more appropriately put around this page as it does not appear to require any detailed knowledge that has not been covered.

This page should be renamed, reorganized, and/or rewritten
I do not understand how "Next steps" summarizes the contents of this page. I recommend that this page is reorganized so that it flows better and complies with the Haskell/Notes_for_contributors page. Is this being covered by the "reorganization" of the beginners' track? --Digichoron (discuss • contribs) 00:18, 5 April 2011 (UTC)

Also, it seems to assume a lot of prior knowledge of Haskell (such as partial application) that should be replaced with simpler examples. --Digichoron (discuss • contribs) 00:27, 5 April 2011 (UTC)


 * Yup, it's not particularly well organized at the moment. Which is not surprising, this book was written by volunteers :-). Your recent contributions are most welcome.
 * --apfe&lambda;mus 08:04, 6 April 2011 (UTC)


 * Why not call the page "Conditionals and Pattern Matching", and move the last part on "let" to the "Variables and functions" section next to "where" since these two are close.
 * --Fritzicato (discuss • contribs) 22:23, 27 December 2020 (UTC)

Let Bindings chapter could add an explanation when to use let vs. where
In a previous section the "where" clause was already introduced. In this chapter/module the "Let bindings" sections introduces the "let/in" keywords. I think it would be appropriate to hint to the already introduced "where" clause and maybe explain how it is different from "let/in".

2012-04-01 reorganization
I just finished a long overdue cleanup of this chapter, so that it doesn't stick like a sore thumb on the "new" structure of the early chapters. The major changes were:


 * Removed the section about case expressions, leaving just if expressions and piece-wise definitions (which have more immediate applications in the following few chapters and are arguably easier to explain at this stage). case is now much further ahead, on the "Control structures" chapter - which, in turn, now has a definite reason to exist!


 * Pruned _ from the piece-wise example, as without case expressions it becomes an unnecessary distraction until we tackle recursion two chapters ahead.


 * Removed most of the indentation section, leaving just a warning and a forward pointer incorporated to the let section.


 * Removed the half of the composition section which discussed (.) and moved it to the "More on functions" chapter. The other half is not essential either, but it is a quite simple point which serves as a good pretext to leave the note on Prelude here (at least while the "Building vocabulary" chapter still does not exist).


 * Condensed the let section a bit so that it plays better alongside the where presentation and examples in previous modules.

That covers most of the suggestions by Digichoron and Reirob. Note that I still couldn't think of a sane title for the chapter, nor an adequate lead text, and that there is still a strong case for eventually dismantling it completely and dispersing the contents throughout the book. But hopefully it is at least tolerable in its current form. Duplode (discuss • contribs) 08:07, 1 April 2012 (UTC)

Next step of reorganization
This chapter has just gained a lifeline. By combining Apfelmus' plans from 2010 on how to introduce pattern matching in the Basics with my own feelings about the matter, I expanded the "Piece-wise definitions" to a real introduction about pattern matching. A few extra comments: --Duplode (discuss • contribs) 06:16, 5 April 2012 (UTC)
 * No mention was made of pattern matching on lists or tuples, on the grounds that it would be too much to take and there would not be good examples easy at reach. It is better to introduce (x:xs) and such right in the middle of the Recursion chapter, as it is now (I will just rework that a bit to weed out redundancies).
 * I opted to leave that subtle mistake in the third example and then immediately ask readers to find it through an exercise because I felt it would be more fun that way. Feel free to change that if you feel this kind of didactic strategy is too risky.
 * As for the remainder of the chapter, I guess most of it will eventually be moved away. let bindings can go to "More on functions" as soon as we ensure there are no examples relying on let...in in the intervening chapters; and function composition should be moved to "Building a vocabulary" when that comes into being (I am starting to see a way to pull it off even while we don't have cheat sheets or an ample assortment of exercises). I believe that if/then/else can stay here, though: it is a small section, the construct is easy to understand and is convenient to mention it here so that we can keep the examples in Simple IO. Additionally, I would like to retain the first example in the pattern matching for shock value :-D
 * If the chapter is not going to be just about pattern matching, however, that means we still lack a good name. Maybe it can stay as "Next steps" for the moment :)


 * Note that since then I changed my mind and brought (x:xs) here. --Duplode (discuss • contribs) 21:56, 15 April 2012 (UTC)

Samples/Excercise
Since I find the exercises very insightful, especially for beginners I am curious for the guards a combination with lists. e.g. if the very first element (head) of a list is 1 then return the last elements, while if it is 0 then return an empty list. With given case [2,5,19] and call with cons. Or something like this, perhaps a little bit more elaborated sample ;) but anyway to show how list would cause at the very beginning I have had my troubles with 'How to return a list (resp. elements of it)?'

AND the side-note: The exercise would be great just before Tuple and list patterns cause then little bit thinking how it should work is done in advance for the solution details just refer to the text.


 * The first suggestion could become a nice exercise, though I'd probably use some other condition rather than equality (as equality tests on the head of a list are better done with pattern matching). This chapter could do with a few more exercises. Duplode (discuss • contribs) 05:10, 13 April 2014 (UTC)

let bindings
Question: From the text it is not really clear what is the difference to the  statement. Is this just synthetic sugar or is there some real benefit? Cause I guess the  binding could be written as well as   binding (for the quadratic solution).


 * They serve the same purpose; as for the differences, broadly speaking,  can be easier to read than , but   can be used in more places. These differences are covered in Haskell/More on functions. By the way, the main reason   is mentioned in this chapter is to provide context for presenting   within   blocks in Haskell/Simple input and output - one of the cases in which   is not enough. Duplode (discuss • contribs) 05:21, 13 April 2014 (UTC)