This is a blog for reflection on Programming Language part 1 at coursera produced by UW(Universit Washington). The design for this course is to help developer better understand what is the programming language and how does functional programming differs from object-oriented programming. And in the first part, we will use a language called SML(Standard ML).
For the first two weeks, the course mainly covers the basic of SML(synatx, list...). I have to say at the first look, this language is quite like Javascript mix with rust. While, if we dive into this language, we can find some interesting points. Like the variable is immutable, such immutable is not like mut
in rust. It just doesn't have the concept of assignment on value. Instead, it introduces another concept called shadowing and binding. In this case, binding works for binding a specific value to a variable and shadowing is for re-binding a value on a existed variable(such process is quite like assignment). And due to this feature, the =
can perform the role of binding value(if the right is a value) and the role of judging value equality(if the right is variable). And this is quite confusing when I first time touched this language.
In addition, this week, it also introduces some basic thinking in the functional programming and let ... in ... done
syntax. The let ... in ... done
may look familiar if you have tried pascal. Basically, it allow you to introduce some local variable and function into the current scope. The most important thing this week, is the recursive way of solving problem. This might be the most trick part, since recursion might be abstract in some cases. And in such a language that does not have any loop feature(so far from what I know), it forces you to rethink all the patterns you have built in the past coding life. Like, we all know we can step through an array using recursion by passing its sub-array. Such operation seems to go against the OOP(Object-oriented programming) thinking.
On more thing, is the list operations. In the first week, it introduces operations:
hd
that will return the first element in the list.tl
it will return a new list with every element but the firste1::a1
that can add one elemente1
to the head ofa1
a1@a2
that can appenda2
to the tail ofa1
. Note: we can use this operation to achieveappend
in python. If we want to appende1
to the tail ofa1
, we can usea1@[e1]
.
At the end, about the first assignment, it is not so hard once we can the sense of recursion. Here is the link for the first assignment.