Lecture -*- Outline -*- * lexical matters in Haskell (Thompson 3.7, Davie 2.14, appendix C.2-3) ** important and unusual lexical conventions ------------------------------------------ IMPORTANT AND UNUSUAL LEXICAL CONVENTIONS - Case matters identifiers: fact, x y constructors: Rational, Stack - Layout (white space) matters: (if omit braces and semicolons, following "where", "let", "do", and "of") Example: let x = 3 y = 4 in x + y ==> let {x = 3 ;y = 4 }in x + y ------------------------------------------ simplified layout rules: first token determines indentation level => { same indentation as first token => ; less indentation => } Watch out, you can get syntax errors from bad indentation! see sections 2.7 and 10.3 of the Haskell report for details ** identifiers and operators (Thompson 1.7, Davie 2.14.2) ------------------------------------------ IDENTIFIERS (NOT INFIX) can use letters, digits, primes and underscores (_) CASE MATTERS varids: start with a-z or unicode lowercase letter examples pythag, fac, x, y', x3'n_, aGoodId conids: start with A-Z or unicode title case letter Examples: Stack, Rational, Typ'_3 ------------------------------------------ ------------------------------------------ OPERATORS Examples: +, -, !!, ++, ==, /= :, :# Notes: 1. Drawn from: !#$%&*+./<=>?@\^|-~: and unicode symbols and punctuation 2. An operator is a constructor if it starts with : 3. All operators are infix except unary negation (-) 4. Any identifer can be made into an infix operator using backquotes 3 `div` 4 5. An infix operator can be used as an identifier when put in parentheses (+) 3 4 ------------------------------------------ Because operator strings are maximal length strings of symbols, instead of 2*-3 you have to write 2*(-3) or 2 * -3.