Haskell

From Code Self Study Wiki
Jump to: navigation, search

This page contains notes and resources about Haskell programming.

Basics[edit]

When using negative numbers, put them in parentheses: 2 * (-3).

Not equals is: 5 /= 3

Functions[edit]

There are infix functions like * and +, and prefix functions like succ 5 (which returns 6) and min 5 7 (which returns 5). Watch out for order, because functions are calculated first.

You can turn a prefix function into an infix function by putting the function name in backticks:

-- This:
div 25 5
 
-- Can also be written as:
25 `div` 5

Lists[edit]

  • Homogenous
  • Get elements from lists: [1,2,3] !! 2
  • Combine lists with ++
  • When combining two lists, Haskell will walk up all the items in the left side. You can put something at the beginning of the list with the : (a.k.a. cons) operator.
-- Combine two lists
[1,2,3] ++ [4,5,6]
 
-- Put something on the beginning of a list
0:[1,2,3]

GHCI[edit]

If you're in ghci, use the let keyword to define names.

Editor Config[edit]

Vim[edit]

Sublime Text[edit]

Atom[edit]

  • TODO

Emacs[edit]

  • TODO

Resources[edit]

More about the language:

Parsers & Lexers[edit]

See Also[edit]