Just for my own comprehension, I took some notes as I read through the first chapter of Real World Haskell[1]. If only to serve as a way to validate my conclusions, I've decided to post my notes here. Either way, I think sharing our learning experiences would be a good way to provoke discussion and encourage cooperation.
- Negative numbers must be surrounded by parentheses
- A trade-off, but allows us to define new operators easily
- 0 not synonymous with False, nor is non-zero synonymous with True
- True && 1 will fail, because 1 is not a Bool
- != in Haskell is /=, logical negation uses `not Function`
- Operators have numeric precedence values
- Use :info (+) to find precedence value for the + function
- Associativity of operators defined by infix(l|r)
1 + 2 + 3 == (1 + 2) + 3
1 ^ 2 ^ 3 == 1 ^ (2 ^ 3)
- List elements must be of same type
- "cons" operator (:) - used to add element to front of list
- Example: 1 : [2,3]
- Type: (:) :: a -> [a] -> [a]
- [1,2] : 3 and [1] : [2,3] will fail
- First arg must be an element, second arg must be a list
- As in C, strings are lists of characters
- Corollary: 'f':"oo" == "f" ++ "oo"
- ghci
- :set +t in ghci will print types after every expression entered
- `it` variable refers to most recently evaluated expression
- Similar to `_` in Ruby's irb
- Will not change upon failed expressions
--
Jay