While going through the programming languages course on Coursera, I learned that ML all ML functions take one argument and return one argument.

So in ML when you see a function like this,

fun sum (x1, x2) = x1 + x2;

Or

fun full_name {first_name=x, last_name=y} = x ^ " " ^ y

Both of these functions have one thing in common, they take one argument!

Every time you write a multi-argument function in ML, we are really writing one-argument functions that take in a tuple as an argument and ML uses pattern-matching to extract the pieces

In the case of the first function, sum, the arguments x1 & x2 are essentially a tuple that will get unpacked and the tuples first and second element will be binded to variables x1 and x2 inside the function.

This got me thinking about python and whether or not every function in python is also a one argument function, in some way or to some extent. I don’t know but I was helping someone here at RC and I told them you can use pythons enumerate to iterate through your list. Then the person told me they’re iterating through a list of 2-elemement-tuples which then made me reocmmend code that pretty much had this effect…

stuff = [('jane', 'doe'), ('john', 'doe')]

for i, (first_name, last_name) in enumerate(stuff):
    print("Person {} is {} {}".format(i+1, first_name, last_name))

And this will result in the program printing,

Person 1 is jane doe

Person 2 is john doe

I guess what I’m trying to get at here is that I learned that ML uses ‘pattern-matching’ to do stuff in a lot of places and that made me think about whether or not works like that too**. I then applied this intuition of pattern matching to unpacking data a tuple in a tuple in pythons for-loop and it worked.

But I guess I should’ve known python can do this because I’ve used pythons pattern matching primitives before. In things like packing a tuple of value.

from multiprocessing import Pipe

fd_read, fd_write = Pipe()

Meh… wtv..