[Haskell-cafe] [ANN] Haskell Cheatsheet v1.0

Justin Bailey jgbailey at gmail.com
Sat Oct 11 18:31:22 EDT 2008


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 <tphyahoo at gmail.com> wrote:
> 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 at thartman-laptop:~/Desktop>thartman_haskell_oneliners
>  ghc -e '1+2'
>
> thartman at 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-tutorial/
>
> thartman at 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 at 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 <jgbailey at gmail.com>:
>> 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 at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>


More information about the Haskell-Cafe mailing list