Category Archives: fun

Answering Exam Questions

Show in detail… If you’re required to show that something holds for a set of given functions, use certain base cases. For example in the 08-09 paper you are given some boolean algebra laws and asked to show that another … Continue reading

Posted in fun, lecture | Leave a comment

Interactive Haskell programs, a primer

Functions There are 3 important functions when dealing with interactive Haskell programs: interact interact takes a function of type String -> String, and the entire input from stdin is passed to this function as its input, and the resulting string … Continue reading

Posted in fun, lecture | Leave a comment

Proving Equivalences

We are asking the question How can we establish whether two functional expressions are equivalent (interchangeable)? You can’t just test across a few results/arguments; there may be an infinite number of possible arguments. Instead, you can use maths style proving … Continue reading

Posted in fun, lecture | Leave a comment

Instantiation and Strictness

Be careful when doing program transformation with regards to strictness. The problem is sometimes your function just passes a variable straight through as input. When this happens, ‘undefined’ can also be passed through just fine. But if you perform program … Continue reading

Posted in fun, lecture | Leave a comment

A Propositional Simplifier

We want to make something that derive clausal forms of formulae in propositional logic. Remember on the slides/notes that > means ‘implies’. | means or. You just do a specific sequence of actions to simplify. Can see this on the … Continue reading

Posted in fun, lecture | Leave a comment

Interactive Functional Programs

The important bit: Don’t think about sequence. Describe the whole expected output, and then use lazy evaluation to make this act ‘interactively’.

Posted in fun, lecture | Leave a comment

Infinite Data Structures

Functions are essentially infinite pairs of input and output, so why not have data with infinite components? Some examples The infinitely long list of spaces: white :: String — Remember a string is a list of characters white = ' … Continue reading

Posted in fun, lecture | Leave a comment

Removing Pointless Code

Lambda functions Backslash in Haskell is lambda, e.g. (\x c -> x == e || c) Removing pointless stuff Here’s an example: reverse xs = foldl snoc [] xs where snoc ys y = y : ys reverse = foldl … Continue reading

Posted in fun, lecture | Leave a comment

Locality

Summary Locality of names Generalisation as a programming tactic, and generalisation in Haskell. Local Definitions Haskell can support local definitions. I used this in the practical. It takes the form: equation where local equations You can also use let, not … Continue reading

Posted in fun, lecture | Leave a comment

Higher Order Functions

Recap about list reversal Something to bear in mind – if the list seems to be in the wrong order, use an accumulator to reverse as you go along. Higher order functions (with regards to generalisation) Remember that a higher … Continue reading

Posted in fun, lecture | Leave a comment