
All, I've created a "cheat sheet" for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included. If you install with "cabal install cheatsheet", run "cheatsheet" afterwards and the program will tell you where the PDF is located. The audience for this document is beginning to intermediate Haskell programmers. I found it difficult to look up some of the less-used syntax and other language stumbling blocks as I learned Haskell over the last few years, so I hope this document can help others in the future. This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2]. Justin [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git

Thank you for your work! I just glanced over it but I'll suggest it to be linked to from the homepage of my university's functional programming course. However, thirteen pages can hardly be called "cheatsheet". It's more like a quick reference. You could add [100,99..] "infinite liste of numbers from 100 downwards" to you "numbers" section, as it is an example where the range does go backward. Adrian Am 11.10.2008 um 01:08 schrieb Justin Bailey:
All,
I've created a "cheat sheet" for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included.
If you install with "cabal install cheatsheet", run "cheatsheet" afterwards and the program will tell you where the PDF is located.
The audience for this document is beginning to intermediate Haskell programmers. I found it difficult to look up some of the less-used syntax and other language stumbling blocks as I learned Haskell over the last few years, so I hope this document can help others in the future.
This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2].
Justin
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Very nice!
I have my own cheat list, which are haskell commands I find useful but
find inconvenient or difficult to look up in the supplied
documentation. I actually hardwire my cheats into .bashrc doing
something like
thartman_haskell_cheatting() {
cat << EOF
blah blah
cheat
}
so i can quickly see all my haskell cheats using tab completion. but a
pdf is even nicer :)
**************************
thartman@thartman-laptop:~/Desktop>thartman_haskell_oneliners
ghc -e '1+2'
thartman@thartman-laptop:~/Desktop>thartman_haskell_regex_hints
cabal install pcre-regex
Most likely want:
Prelude Text.Regex.PCRE> "user123" =~ "^(user)(\d*)$" ::
(String,String,String,[String])
("","user123","",["user","123"])
That is: (before match, match, after match, subgroups)
or maybe
Prelude Text.Regex.PCRE> "user123 user456" =~ "(u(se)r)(\d*)" :: [[String]]
[["user123","user","se","123"],["user456","user","se","456"]]
if you need all submatches of all matches
since
Prelude Text.Regex.PCRE> "user123 user456" =~ "(user)(\d*)" ::
(String,String,String,[String])
("","user123"," user456",["user","123"])
doesn't quite do what I want -- no submatches
and there's no instance for :: (String,String,String,[String])
I don't need all submatches of all matches very often though.
:: Bool -- did it match
:: String -- first match
:: [String] -- every match
:: :: (String,String,String) -- before, matched, after
http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutor...
thartman@thartman-laptop:~/Desktop>thartman_haskell_testing_things
import Data.Test.HUnit
runTestTT $ TestCase $ assertEqual "meh" 1 2
runTestTT $ TestList [ TestCase $ assertEqual "meh" 1 2 ]
thartman@thartman-laptop:~/Desktop>thartman_haskell_hints
offline documentation:
ghc-pkg describe bytestring | grep -i doc
or probably just
haddock-interfaces:
/usr/local/share/doc/ghc/libraries/bytestring/bytestring.haddock
haddock-html: /usr/local/share/doc/ghc/libraries/bytestring
note to self:
start using cabal install --global (or whatever the flag is)
so all documentation is browsable from one place
Use language pragmas, with commas
And you can't put LANGUAGE and OPTIONS_GHC in the same pragma
{-# LANGUAGE NoMonomorphismRestriction, PatternSignatures #-}
{-# OPTIONS -fglasgow-exts #-}
Debugging
toVal.hs:30:17:
Couldn't match expected type 'blee'
against inferred type 'bleh'
bleh is whatever is at 30:17
blee is something that's wanted by whatever is calling the value at 30:17
If the error is "in the definition of" some function,
then probably one function case conflicts with another, you can
ignore other functions.
In this case you will only get one line:col to look at.
If there are more than one line:col to look at, possibly separate
functions are in conflict.
So, smart to always fix "in the definition of" type errors first.
Still baffled? Won't compile?
Give top-level functions type signatures. Won't hurt, might help.
:set -fwarn-missing-signatures
or {-# OPTIONS -fwarn-missing-signatures #-}
Start commenting out calling functions until it compiles, and then
look at the signatures.
And then type the signatures in explicitly... does something look funny?
Like, wrong number of args? Maybe currying went wrong.
tag and bundle a distribution:
darcs tag 0.2
cabal configure
cabal sdist
cd dist; unzip, verify install does the right thing
http://hackage.haskell.org/packages/upload.html
check upload, and upload.
see also http://en.wikibooks.org/wiki/Haskell/Packaging
group module imports from multiple modules in one place:
module MyInductiveGraph (
module Data.Graph.Inductive,
module EnoughFlow
)
where
import Data.Graph.Inductive
import EnoughFlow
**************************
2008/10/11 Justin Bailey
All,
I've created a "cheat sheet" for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included.
If you install with "cabal install cheatsheet", run "cheatsheet" afterwards and the program will tell you where the PDF is located.
The audience for this document is beginning to intermediate Haskell programmers. I found it difficult to look up some of the less-used syntax and other language stumbling blocks as I learned Haskell over the last few years, so I hope this document can help others in the future.
This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2].
Justin
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thanks to everyone for their feedback. I've made some updates and
posted the PDF to my blog:
http://blog.codeslower.com/2008/10/The-Haskell-Cheatsheet
On Sat, Oct 11, 2008 at 4:33 AM, Thomas Hartman
Very nice!
I have my own cheat list, which are haskell commands I find useful but find inconvenient or difficult to look up in the supplied documentation. I actually hardwire my cheats into .bashrc doing something like
thartman_haskell_cheatting() {
cat << EOF blah blah cheat
}
so i can quickly see all my haskell cheats using tab completion. but a pdf is even nicer :)
**************************
thartman@thartman-laptop:~/Desktop>thartman_haskell_oneliners ghc -e '1+2'
thartman@thartman-laptop:~/Desktop>thartman_haskell_regex_hints cabal install pcre-regex
Most likely want:
Prelude Text.Regex.PCRE> "user123" =~ "^(user)(\d*)$" :: (String,String,String,[String]) ("","user123","",["user","123"]) That is: (before match, match, after match, subgroups)
or maybe Prelude Text.Regex.PCRE> "user123 user456" =~ "(u(se)r)(\d*)" :: [[String]] [["user123","user","se","123"],["user456","user","se","456"]] if you need all submatches of all matches
since Prelude Text.Regex.PCRE> "user123 user456" =~ "(user)(\d*)" :: (String,String,String,[String]) ("","user123"," user456",["user","123"]) doesn't quite do what I want -- no submatches and there's no instance for :: (String,String,String,[String]) I don't need all submatches of all matches very often though.
:: Bool -- did it match :: String -- first match :: [String] -- every match :: :: (String,String,String) -- before, matched, after
http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutor...
thartman@thartman-laptop:~/Desktop>thartman_haskell_testing_things import Data.Test.HUnit runTestTT $ TestCase $ assertEqual "meh" 1 2 runTestTT $ TestList [ TestCase $ assertEqual "meh" 1 2 ]
thartman@thartman-laptop:~/Desktop>thartman_haskell_hints offline documentation: ghc-pkg describe bytestring | grep -i doc or probably just haddock-interfaces: /usr/local/share/doc/ghc/libraries/bytestring/bytestring.haddock haddock-html: /usr/local/share/doc/ghc/libraries/bytestring note to self: start using cabal install --global (or whatever the flag is) so all documentation is browsable from one place
Use language pragmas, with commas And you can't put LANGUAGE and OPTIONS_GHC in the same pragma {-# LANGUAGE NoMonomorphismRestriction, PatternSignatures #-} {-# OPTIONS -fglasgow-exts #-}
Debugging
toVal.hs:30:17: Couldn't match expected type 'blee' against inferred type 'bleh' bleh is whatever is at 30:17 blee is something that's wanted by whatever is calling the value at 30:17
If the error is "in the definition of" some function, then probably one function case conflicts with another, you can ignore other functions. In this case you will only get one line:col to look at. If there are more than one line:col to look at, possibly separate functions are in conflict. So, smart to always fix "in the definition of" type errors first.
Still baffled? Won't compile? Give top-level functions type signatures. Won't hurt, might help. :set -fwarn-missing-signatures or {-# OPTIONS -fwarn-missing-signatures #-} Start commenting out calling functions until it compiles, and then look at the signatures. And then type the signatures in explicitly... does something look funny? Like, wrong number of args? Maybe currying went wrong.
tag and bundle a distribution: darcs tag 0.2 cabal configure cabal sdist cd dist; unzip, verify install does the right thing http://hackage.haskell.org/packages/upload.html check upload, and upload. see also http://en.wikibooks.org/wiki/Haskell/Packaging
group module imports from multiple modules in one place: module MyInductiveGraph ( module Data.Graph.Inductive, module EnoughFlow ) where import Data.Graph.Inductive import EnoughFlow
************************** 2008/10/11 Justin Bailey
: All,
I've created a "cheat sheet" for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included.
If you install with "cabal install cheatsheet", run "cheatsheet" afterwards and the program will tell you where the PDF is located.
The audience for this document is beginning to intermediate Haskell programmers. I found it difficult to look up some of the less-used syntax and other language stumbling blocks as I learned Haskell over the last few years, so I hope this document can help others in the future.
This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2].
Justin
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Justin Bailey wrote:
Thanks to everyone for their feedback. I've made some updates and posted the PDF to my blog:
I was wondering why there isn't a PDF directly downloadable anywhere... ;-) FWIW, I just learned something by looking at this. I was under the impression that a literal number can have *any* type, and therefore "1" and "1.0" are completely equivilent. Apparently this is untrue. (!) Your "numbers" section is actually mostly list comprehensions. While it's interesting that you need a space between ".." and "-" for negative numbers, this wasn't immediately clear from reading your text. Maybe it would be better to write that as a sentence? (Or just format the correct syntax in monotype so the space is more obvious.)

On Saturday 11 October 2008 01:08:15 Justin Bailey wrote:
This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2].
Justin
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git
Looks good! Some minor issues: - sometimes it is a bit verbose for a cheatsheet; for example the reference to language C in the section about the layout rule. - in the section about strings, you give an example of a syntax error; it would be sufficient to show what is right. - in the section about operator precedence you define 'div1' to be right associative. Instead, you could show where right associativity is actually useful (>>=, ...). - The explanation of the layout rule is wrong. If you define more than one value in a let declaration, then it is only required that the identifiers start on the same column. - When I started to learn Haskell, I had problems with the use of (.) and ($). I had learned what function application and lambda abstractions look like, but then I looked at Haskell code written by experienced Haskellers and found expressions like (map (succ . succ) $ 1:xs) that I did not understand. A small section describing how to read such expressions could be useful for beginners. - the section about do-notation is more a mini-tutorial than a cheatsheet. Instead, you could show two or three examples that demonstrate how do- notation, list comprehensions and the operator >>= relate. That is what I had to look up more than once until I got used to it. There is also an example of what is wrong, where showing the right thing would have sufficed.

On Sat, Oct 11, 2008 at 5:30 AM, Holger Siegel
- The explanation of the layout rule is wrong. If you define more than one value in a let declaration, then it is only required that the identifiers start on the same column.
Thank you - updated.
- When I started to learn Haskell, I had problems with the use of (.) and ($). I had learned what function application and lambda abstractions look like, but then I looked at Haskell code written by experienced Haskellers and found expressions like (map (succ . succ) $ 1:xs) that I did not understand. A small section describing how to read such expressions could be useful for beginners.
Me too. I had a section on that originally but cut it due to time. Patches are always welcome :)
- the section about do-notation is more a mini-tutorial than a cheatsheet. Instead, you could show two or three examples that demonstrate how do- notation, list comprehensions and the operator >>= relate. That is what I had to look up more than once until I got used to it. There is also an example of what is wrong, where showing the right thing would have sufficed.
True, but I think it's helpful. That stuff really confused me at first. Justin

On Fri, 10 Oct 2008, Justin Bailey wrote:
I've created a "cheat sheet" for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included.
..
The audience for this document is beginning to intermediate Haskell programmers. I found it difficult to look up some of the less-used syntax and other language stumbling blocks as I learned Haskell over the last few years, so I hope this document can help others in the future.
..
Justin
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git _______________________________________________
Justin (and everyone now contributing to this), thanks. This type of thing is very helpful. There is a well-known one-page cheat-sheet like this for Perl5 (and a newer one for Perl6 too). You can see it by typing `perldoc perlcheat` on a system with Perl. I wonder if we don't need something like that. On a related note, I had come up with this short list to help with how to read the Haskell symbols. I email this out when trying to get new people started: ----- Haskell symbology One thing that I found very difficult at first was how to read a lot of the symbols in the Haskell code. I made up a small cheat-sheet that explains how to read some of it: Some definitions of Haskell symbols: :: "has type" -> "to" The type 'Integer -> Integer' takes Integer as an argument and evaluates to an Integer. We say this type is "Integer to Integer" => "evaluates" or "reduces to" Used in function type signatures, read something like this: foo :: (Bar b) => b -> c For all instances of type class Bar (here referred to as b), foo is a function from b to c. Or foo "has type" b to c. [a] "list of a" The family of types consisting of, for every type a, the type of lists of a. : "cons" List cons operator, adds first argument to the front of second, part of the List monad: (:) :: a -> [a] -> [a] Read: cons has type a to list of a to list of a !! List index operator [ 1, 2, 3 ] !! 1 = 2 (lists are 0-based) (!!) :: [a] -> Int -> a Read: (!!) has type list of a to Int to a | "such that" <- "drawn from"
= "bind" Part of class Monad
"then" Part of class Monad
-- Dino Morelli email: dino@ui3.info web: http://ui3.info/d/ irc: dino- pubkey: http://ui3.info/d/dino-4AA4F02D-pub.gpg

On Fri, Oct 10, 2008 at 7:08 PM, Justin Bailey
I've created a "cheat sheet" for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included.
It looks very nice, if a bit verbose. One minor comment is that on page 4 you give a "type signature" for if-then-else. I would contend that it should be Bool -> a -> a -> a, instead. steve

On Fri, Oct 10, 2008 at 7:08 PM, Justin Bailey
This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2].
On page 1, you list 'return' as a reserved word, but it isn't. It's just a function, and in fact you can redefine it.
participants (8)
-
Adrian Neumann
-
Andrew Coppin
-
Dino Morelli
-
Holger Siegel
-
Justin Bailey
-
Kurt Hutchinson
-
Stephen Hicks
-
Thomas Hartman