This page contains notes and resources about Haskell programming.
When using negative numbers, put them in parentheses:
2 * (-3).
Not equals is:
5 /= 3
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
- 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
-- Combine two lists [1,2,3] ++ [4,5,6] -- Put something on the beginning of a list 0:[1,2,3]
If you're in ghci, use the
let keyword to define names.
- The Haskell Road to Logic, Maths and Programming
- Where to start?
- Write Yourself a Scheme in 48 Hours
- Type Theory and Functional Programming
- What is the coolest snippet of Haskell code?
More about the language:
Parsers & Lexers
- Lecture 4: Implementing Lexers and Parsers
- Parsing a simple imperative language
- How to implement lexical analyser and parser in Haskell