Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| 
                    pp:scala-project [2022/01/07 14:55] pdmatei  | 
                
                    pp:scala-project [2022/01/12 11:58] (current) pdmatei  | 
            ||
|---|---|---|---|
| Line 108: | Line 108: | ||
| </code> | </code> | ||
| + | ===== 4. TDAs ====== | ||
| + | Object-Oriented decomposition (the classical TDAs vs OO) | ||
| + | Functional decompositions (case classes) | ||
| + | <code scala> | ||
| + | def eval(e: Expr): Int = e match | ||
| + | case Number(n) => n | ||
| + | case Sum(e1,e2) => eval(e1) + eval(e2) | ||
| + | </code> | ||
| + | |||
| + | |||
| + | <code scala> | ||
| + | val l = 1 :: 2 :: 3 :: Nil | ||
| + | </code> | ||
| + | |||
| + | **Enums** (TDAs) | ||
| + | <code scala> | ||
| + | enum Expr: | ||
| + | case Var (s: String) | ||
| + | case Number (n: Int) | ||
| + | case Sum(e1: Expr, e2: Expr) | ||
| + | case Prod(e1: Expr, e2: Expr) | ||
| + | </code> | ||
| + | |||
| + | Type bounds in generics | ||
| + | <code scala> | ||
| + | def asseertAllPos [S <: IntSet] (r: S): S = ... | ||
| + | </code> | ||