Talk:Haskell/Next steps

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

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)

Contents

[edit] 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)

[edit] 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)


  • 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:

In order to compile your .hs file into an executable program, do the following (in Windows):

  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.

[edit] 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:

Note

Commands like :load are part of GHCi rather than Haskell syntax. A full listing of commands available from the GHCi prompt is available by entering :? or from the GHCi documentation.

Abdelazer 00:09, 1 June 2007 (UTC)

[edit] Magic _

f _ = -1 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 f 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)

[edit] 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.

[edit] math tags

I think that <math> 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. —Toby Bartels (talk) 15:18, 22 October 2008 (UTC)

[edit] 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)

[edit] 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.) —Toby Bartels (talk) 15:24, 22 October 2008 (UTC)

Order doesn't matter for declarations (i.e. first x=.. then y=.. or the other way round) but it does matter for pattern matching (i.e. first the case f xs []=.. and then f [] ys = .. or the other way round). That seems to be what section 1.3 and 2.3 want to say.
-- apfeλ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. —Toby Bartels (talk) 01:48, 25 October 2008 (UTC)

[edit] 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λmus 07:37, 20 September 2009 (UTC)