Tip:
Highlight text to annotate it
X
Hi I am Rusi In an earlier life a computer scientist
An old hand at Lisp, Miranda, gofer and their modern cousin Haskell Also python
For the length of this course however, I'll be your friend lambda
Lets start with a classical newbie example This is python but could almost be any language
One of the first pieces of code that a newbie learns is how to swap two variables
There are many ways of doing this 1 the standard way,
2 using an extra stack 3 clever use of xor
4.parallel hardware
And so on and so forth
And all these ways are the 'how' Getting entangled in this
makes us lose track of the 'what'
Which can be written in python as simply as
x,y = y,x
One more little example
Look at these two alternative ways in python to append two lists
They seem quite similar Yet they are deeply different
After the plus nothing is changed After the extend, x is different, its changed
We say that plus is functional code Extend is imperative or object oriented
While these two examples seem too trivial they carry an important idea:
the paradigm difference between imperative and functional programming
Note: To be strictly correct
we are talking of the paradigm not the semantics which is imperative in any case for assignment
Programming is a dual natured activity Sometimes we need to play with ideas
Sometimes to realize them with the nitty gritties of current technology
For us the idea playground will be haskell And python will be the gateway to current
technology
In particular we will not be concentrating much on advanced type hackery and such in
Haskell
Likewise for us python being the realizer of functional programming
we will see how to replace long ungly object oriented code by cute functional one-liners
And so Like harmony singing
Our course will flow In two voices
Playing with ideas in Haskell And hacking code in python
And just in case you think 'functional programming' brings before your eyes, images of a frightening
world Of monstrous polymorphic types
Terrifying higher order functions That mysterious self-swallowing serpent the
Y-combinator And of course that king of incomprehensibility
-- monads
Then you are mistaken We find the same
in a beautiful world of values
Concrete data structures where constructors and destructors are the same
Equational function definitions Pattern matching
The sum of which starting with indentation
makes for strikingly beautiful programs
But beauty does not come at the cost of richness Our value world is rich
Recursive data structures First class data constructors
Higher order functions and combinators make for a rich clean semantics
And underneath all this realizing it
is the lambda calculus machine
What the programmer declarates The machine imperates
This is the theme of the course For us
Programming is the dance between this declaration of the programmer
and the imperation of the machine