Functional vs. OO programming - Examples

Course Website: http://cs.oberlin.edu/~jwalker/exco/
Gelernter page 296.
"A class definintion is a higher order function."

Higher Order Functions and Commands

A class is equivalent to a function. However OO and functional place different restrictions on there use so they don't appear to be the same. Similarities can be seen through the command pattern.

ML polymorphism vs. Methods and Visitor

In ML functions are ploymorphic on all arguments instead of just the first this provides an interesting alternative to visitors. However, it really changes one perspective away from the architecting created by OO languages. It does however allow two hierchies to be varient unlike the visitor.

let add_num n1 n2 =
   match (n1, n2) with
     (Int i1, Int i2) ->
       (* Check for overflow of integer addition *)
       if sign_int i1 = sign_int i2 && sign_int(i1 + i2) <> sign_int i1
       then Float(float i1 +. float i2)
       else Int(i1 + i2)
   | (Int i1, Float f2) -> Float(float i1 +. f2)
   | (Float f1, Int i2) -> Float(f1 +. float i2)
   | (Float f1, Float f2) -> Float(f1 +. f2)
   | (Error, _) -> Error
   | (_, Error) -> Error;;

Scheme/λ-calculus Boolean Example

See http://occs.cs.oberlin.edu/~jwalker/langDesign/OO_vs_Fun/



jwalker@cs.oberlin.edu