110 likes | 238 Views
Programming Paradigms. CPSC 449 Week 5 Prepared by : Mona Hosseinkhani , Arash Afshar Winter 2014. Department of Computer Science, University of Calgary. Understanding definitions. Alternatives Evaluate on particular inputs Using an implementation (e.g. GHCi )
E N D
Programming Paradigms CPSC 449 Week 5 Prepared by : Mona Hosseinkhani, ArashAfshar Winter 2014 Department of Computer Science, University of Calgary
Understanding definitions • Alternatives • Evaluate on particular inputs • Using an implementation (e.g. GHCi) • By hand (by performing a line by line calculation) • Argue about how it behaves in general • Example
Analyze the behavior in general • Find general properties of length • length [x] = 1 • length (xs ++ ys) = length xs + length ys • We could show • This is called Symbolic Evaluation. • Rather than evaluating length at a particular value, we used a variable x. So for all values of x:
Understanding definitions • Symbolic evaluation is an important part of the proofs. • But we also need another principle: induction to do most proofs for recursive functions • Note that understanding and describing definitions in imperative languages (e.g. Pascal) is very difficult
Program correctness: recall • Test on inputs • Property-based test • Proof
Example • No termination
Lazy evaluation • Evaluate • Haskell evaluates an expression only if its value is actually needed.
Questions hossem@ucalgary.ca
Install bmp package for next assignment • http://hackage.haskell.org/package/bmp • $ cabal update • $ cabal install cabal-install • if the last step is successful execute the following • $ cabal install bmp