Learning Haskell in 2017

Table of Contents

1 Learning Haskell in 2017

1.1 Preface

This is some notes from when I was learning Haskell in 2017.

1.2 Tooling

The main three tools for most general Haskell development, are GHC, Stack and Cabal.

1.2.1 Stack

Project stack.yaml is the Here's a typical scenario:

stack new foo
cd foo 
# ... edit files ..
# .. edit foo.cabal to add dependencies
stack ghci     # do REPL interaction 
stack build   # build project
stack test      # run your unit tests
stack install # install your binary

1.2.2 GHC

foo

1.2.3 Cabal

1.2.4 Other tools

  • Editor integration - Emacs
    • Intero-mode

    Intero for Emacs

    • works with company-mode autocompletion
    • has on-the-fly type-checking (flycheck)
    • Haskell-mode – installing this mode enables haskell mode for haskell files.

    It contains multiple modes though, see C-h f haskell-mode for more info. flycheck, hlint

    • hindent-mode
    • interactive-haskell-mode, haskell-doc-mode (the later depends on the former being active).
  • Git

    Git is a commonly used version control system. Specificially for developing Haskell in git repositories, you might want to consider adding some files to .gitignore echo '.stack-work/' >> .gitignore.

1.3 Random Notes

1.3.1 Points of confusion

  • Exception handling

    There is seemingly no idiomatic and clearcut way of handling exceptions such as exist in other languages. There are options, some more dated than others. Some more complex than others.

    import Control.Exception (try, bracket, catch,catches)
    
  • The many types of text. (tk)

    There is String, which is [Char],Data.Text.Internal.Text, Lazy and Strict, Char8, Word8, ByteString decode, unpack, pack.

    Tools text-show (printT) — http://hackage.haskell.org/package/text-show text-format — https://hackage.haskell.org/package/text-format OverloadedStrings pragma Data.Text.Lens

1.3.2 Packaging

1.4 Resources

1.4.1 Comprehensive articles - reference material

1.4.2 Online course

  • CIS194 Spring 2014, Brent Yorgey is a praised Haskell course. Yorgey has much experience developing freely available Haskell code (see e.g. the diagrams library and typeclassopedia).

1.5 Books

The most commonly mentioned, and freely available Learn You a Haskell for Great Good by Miran Lipovača is a popular choice among beginners. A somewhat dated but much respected book for intermediate Haskell programmers is Real World Haskell by Bryan O'Sullivan, Don Stewart, and John Goerzen.

1.6 Video introductions

1.6.1 Jekor

1.6.2 Amuse-Bouce

1.7 Package troubleshooting

A dependency package broke during compilation, to fix (with cabal) use "cabal get", fix the error and cabal install.

1.8 Errors

  • Control.Exception (exceptions),
  • Control.Exception.Safe
foo bar
baz
   <jmnoz> Can anyone recommend me a "good enough" way to (as a beginner)
             do error handling / exceptions for my command line tool which
             does a bunch of IO?                                        [20:53]
 <monochrom> yes, we can recommend three ways
<Tuplanolla> By "we" he means monochrom.                                [20:54]
     <EvanR> polychrom
     <EvanR> press B to stop evolution
 <monochrom> yes, we are King Monochrom
      <niez> hi, I have problems with latest groundhog and groundhog-utils
             (both from latest git commit), I get: 'Not in scope: type
             constructor or classPhantomDb’' when building groundhog-utils
             (I'm building with stack using lts-7.10 resolver - which
             includes ghc-8.0.1), anyone can help?
     <lyxia> jmnoz: just return Either String values                    [20:55]
     <EvanR> you can use IO exceptions                          [20:56]
     <EvanR> :t throwIO
 <lambdabot> Exception e => e -> IO a
       <hpc> :t bracket
 <lambdabot> IO a -> (a -> IO b) -> (a -> IO c) -> IO c
       <hpc> bracket action handler finalizer                           [20:57]
       <hpc> or something like that
     <EvanR> setup handler body teardown                                [20:58]
     <EvanR> oh theres only 3 args
       <hpc> setup handler body, i suppose
     <EvanR> no finalizer
     <jmnoz> thanks folks. I got confused reading about eitherT, exceptT and
             so forth
       <hpc> jmnoz: you may find yourself writing repetitive exception
             handling code, and then those types will make all the sense in
             the world                                          [20:59]
     <jmnoz> hpc: do you have any public code which you can recommend
             inspecting?                                                [21:00]
       <hpc> but yeah, it takes perspective or just staring at stuff that

1.9 Meta - About this document

1.9.1 Exporting this file - source

  • org-mode settings

    org-html-doctype: html5

    Uses org-ref, hask.bib cite:wiki:xxx

2 Bibliography

bibliography:hask.bib

Author: Jussi Norlund

Created: 2017-12-08 Fri 06:10

Validate