Real World Haskell, Ch.1 notes

1 view
Skip to first unread message

Jay Mendoza

unread,
Jan 16, 2010, 8:03:41 PM1/16/10
to lambda-lam...@googlegroups.com
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

Reply all
Reply to author
Forward
0 new messages