110 likes | 249 Vues
This document delves into the concepts of symbolic evaluation and program correctness within the context of functional programming, particularly using Haskell. It examines definitions, evaluation techniques, and general properties like length functions. It discusses how symbolic evaluation allows for reasoning about program behavior without specific values and emphasizes the significance of inductive reasoning for recursive functions. Examples illustrate lazy evaluation in Haskell, where expressions are computed only when necessary. Additionally, it provides practical guidance on installing necessary Haskell packages for assignments.
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