Some time ago, there was a thread about a "CheatSheet" for Haskell beginners. As I recall, the CheatSheet was more than 12 pages long. For a Haskell tutorial I was running at a conference recently, I needed a "Quick Reference Guide" that would fit onto a single side of A4. So I knocked one together quickly, and it is attached as a PDF. I send it to this list, with permission for anyone to distribute it more widely as they wish, in the hope that it might be useful. Doubtless it is incomplete, and I have no particular desire to fix errors or maintain this document, so if anyone is interested and would like to adopt it, I can pass on the editable sources. It was originally created as an Apple Numbers spreadsheet (simply for speed of creation) but could be converted to Excel or CSV, for import into other tools. Regards, Malcolm
Hi, the reference suggests the use of otherwise (instead of _) as the default pattern in a case expression. While it certainly works, isn’t it bad style, as it shadows Prelude.otherwise: $ cat otherwise.lhs ; runhaskell otherwise.lhs
demo b arg = case b of True -> do print "First arg was True" let g | arg == "Something" = print "Got something" | otherwise = print "Got anything else" g otherwise -> do print "First arg was not True" let g | arg == "Something" = print "Got something" | otherwise = print "Got anything else" g
main = do demo True "Something" demo True "Something else" demo False "Something" demo False "Something else" "First arg was True" "Got something" "First arg was True" "Got anything else" "First arg was not True" "Got something" "First arg was not True" otherwise.lhs: otherwise.lhs:(7,36)-(8,86): Non-exhaustive patterns in function g
I know that this is a contrieved example (using case on a boolean), but in other cases you’ll get strange type errors. So while I think I did it in the past, otherwise should be avoided in case expressions. Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org
The reference includes both pairs and triples under "Tuples," but only pairs under "Bigger types." You may wish to add the following example under "Bigger types": (a, b, c) triple of types a, b, and c (a, b, and c are type variables) Also, the examples under "Tuples" suggest that only pairs and triples are valid tuples, but in fact, n-tuples, where n is any positive integer other than 1, are valid tuples as well. You probably don't need to document the fact that 1-tuples are trivially isomorphic to values in parentheses, but you may wish to include the following line there (the specification of the range for the values of n being optional): (x1, x2, ..., xn) an n-tuple of values (n = 0 or n > 1) Accordingly, you may also wish to add the following corresponding line under "Bigger types" (again, the specification of the range for the values of n being optional): (a1, a2, ..., an) n-tuple of types a1, a2, ..., an (a1, a2, ..., an are type variables, n = 0 or n > 1) -- Benjamin L. Russell On Thu, 6 Nov 2008 13:41:13 +0000, Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> wrote:
Some time ago, there was a thread about a "CheatSheet" for Haskell beginners. As I recall, the CheatSheet was more than 12 pages long.
For a Haskell tutorial I was running at a conference recently, I needed a "Quick Reference Guide" that would fit onto a single side of A4. So I knocked one together quickly, and it is attached as a PDF. I send it to this list, with permission for anyone to distribute it more widely as they wish, in the hope that it might be useful.
Doubtless it is incomplete, and I have no particular desire to fix errors or maintain this document, so if anyone is interested and would like to adopt it, I can pass on the editable sources. It was originally created as an Apple Numbers spreadsheet (simply for speed of creation) but could be converted to Excel or CSV, for import into other tools.
Regards, Malcolm
Malcolm.Wallace:
Some time ago, there was a thread about a "CheatSheet" for Haskell beginners. As I recall, the CheatSheet was more than 12 pages long.
For a Haskell tutorial I was running at a conference recently, I needed a "Quick Reference Guide" that would fit onto a single side of A4. So I knocked one together quickly, and it is attached as a PDF. I send it to this list, with permission for anyone to distribute it more widely as they wish, in the hope that it might be useful.
wonderful. recorded on the wiki, http://haskell.org/haskellwiki/Image:QuickReference.pdf
participants (4)
-
Benjamin L.Russell -
Don Stewart -
Joachim Breitner -
Malcolm Wallace