- Syntax
- Semantics
- Implementation
-
Basics (tail-recursion, higher-order functions)
- See Haskell-basic
-
Closure
- No free-variable
-
Argument Evaluation Strategies
- Call-by-value
- Always evaluate the argument before applying the function/operation
- May result in errors/non-termination when it is not necessary
- Call-by-name
- Arguments are not evaluated: only when needed (referenced) during function application
- Variable capturing problem
- Call-by-name(thunk)
- Thunk: Wrap the argument with a dummy lambda
- May lead to repetitive evaluation
- Call-by-text
- A variation of Call-By-Name
- Use the referencing environment, not the defining environment
- Call-by-need(Lazy evaluation)
- A variation of Call-By-Name
- supported using cache
- no repetitive evaluation
- Call-by-value
-
Environment, static vs. dynamic scoping
a = 100 in h = \x->x+a in twice = \f->\x->f (f x) in let a = 10 in twice h a
- for dynamic scoping:
(x+a)+a = 10+10+10 = 30
- for static scoping:
(x+a)+a = 100+10+10 = 210
- for dynamic scoping:
-
Assignment 2-3; 看得懂稍複雜的Haskell程式
-
Variables in imperative languages: names, locations, values and scopes
-
Memory model:
----------------- | Code | ----------------- | Static data | ----------------- | Stack | ----------------- | | | | ----------------- | Heap | -----------------
- stack and heap
- Garbage and dangling pointers
- dangling pointers:
Pointers that point to deallocated memory locations - Garbage:
Memory (heap) cell that is allocated but cannot be accessed. (No pointers reference it)
- dangling pointers:
-
Data types and type systems (strong vs. weak)
-
Type coercion vs. type cast
-
Type checking: static vs. dynamic check
- Message passing and method lookup
- Dynamic binding of methods
- Inheritance and polymorphism
不管many裡面是colorpoint還是point都可以move()many = new vector(); many[0] = new Point(3, 4); many[1] = new ColorPoint(2, 2, BLUE); many[2] = new Point(1, 5); move_all(many, 2, 4); move_all(vector v, dx, dy)�{ // move all members of vector v by dx and dy� // don’t care the exact kind of points� for (i=0; i<v.length; i++)� v[i].move(dx, dy); }
- Overloading vs. Overriding
- Overriding
- Early vs. Late Binding
By default, the C++ compiler implements early (static) binding;
For virtual functions, the compiler implements dynamic binding
- Early vs. Late Binding
- Overriding