Unit and Nothingness
On a different note…
1. On Procedures and Functions
In FORTRAN and Pascal and Ada, programming languages that I revelled in long ago, there is a distinction drawn between so-called procedures on the one hand and functions on the other. Both are software constructs for doing some work, but whereas a function calculates a tangible result and gives it back to the caller, a procedure does no such thing, performing instead some background operation on behalf of the caller (for instance printing some text to the screen or saving some data in a database).
So in Ada you might write
function Translate( english_word : String ) return String is begin ...translation algorithm here... return swahili_word; end
and
procedure Display( sentence : String ) is begin ...output algorithm here... end
In a sense, functions produce stuff that you can take with you whereas procedures just do stuff.
2. Unifying Them Both
In contrast to this, the languages C, C++, C# and Java have no such distinction. They only have functions.
Well, that’s not quite right, because of course there’s still a need for algorithms that do stuff. And so in place of procedures, these languages define so-called void functions. They produce nothing whence void.
In a hypothetical language might this could take the following form.
function Display( sentence : String ) return void is begin ...output algorithm here... end
To an engineer encountering this stuff for the first time, this notion of void functions is entertaining. It’s novel to reflect on the notion that the void has entered into an otherwise dry world of physics and equations of motion and all that.
But it’s not a confusing concept, so after a few minutes the novelty fades, and you proceed as you always have, writing some functions that produce something and other procedures functions that don’t.
3. void
Isn’t a Type
Now, the languages mentioned above are examples of so-called statically typed languages. That is to say, every algorithm expressed in these languages manipulates things that have a so-called type (String, Integer, Character, …), and these types are explicitly specified by the programmer. So you might wonder, What is this type called void
?
Well, I am not a programming expert, but my understanding is that in fact in these cases, void
isn’t really a type per se. It’s just a hint to the computer that this particular function actually doesn’t return anything.
Hm… It’s a hint that this function isn’t producing anything; that it’s only doing something. In other words, void
is just an annotation that says, Hah! Fooled you. This isn’t really a function at all; it’s a procedure.
4. Introducing Unit
This state of affairs changes a bit in the Scala programming language, a language built on the conceptual foundations of C and Java but one that goes in some fundamentally different directions.
Scala generalizes the notion of void
to a full-fledged type called Unit
. So in Scala you might write something like this.
def Display( sentence : String ) : Unit = { ...output algorithm here... }
Or using the Ada-like pseudocode we’ve used above,
function Display( sentence : String ) return Unit is begin ...output algorithm here... end
The only real difference here is the presence of Unit
instead of void
. But in Scala, this is no minor detail. Whereas the void
of C is a kind of hint, Scala’s Unit
is a bonafide type.
5. A Tangent on the Notion of Unit
Unit
made me do a double-take when I first saw it. After all, using Unit
to represent “nothing” sounds perilously close to the heresy of claiming that 1=0
. It turns out that I’ve run into this heresy before.
Once upon a time I was working with a bunch of rocket scientists. We were building a new space transportation system that was going to take us to orbit, take us to the moon and eventually take us to Mars. One of the projects I was working on involved designing a schema for representing complex datasets in a way that future engineers and software developers could understand long after the original authors were gone. (This system was being designed for the long-haul, an irony given that the project was eventually cancelled.)
I worked with a couple computer science-y, math-y guys from California. They were bright, and they were determined to apply their dreams of ontologies to the problem I was working on. One day we were discussing how to specify … nothing — how to formally indicate that there was nothing there there.
“Can we call this Unit?” Oliver asked.
I was puzzled. Why would we call nothing one?
See the connection, here?
6. Another Tangent
I’m not a computer scientist. Indeed, in an interview question long ago, I was asked some computer science-y, algorithm-theoretical question to which said, “I confess I’m not strong in …” to which the questioner responded, “Aren’t all computer scientists strong in …?” to which I reminded him that my background was in engineering.
Neither am I a mathematician. But let me point out something about Monoids. In abstract algebra, a monoid is a pair (S
,op
) where S
is some set and op
is a binary operation (function) on that set that returns elements of the set. There are some axioms surrounding S
and op
, namely the axioms of closure, associativity and identity.
It’s the notion of identity that is relevant, here. The identity axiom simply stipulates that there is some element in the set S
, let’s call it I
, for which (I op x) = x
for all elements x
in S
.
Hmm… This is a bit abstract. But wait, don’t leave.
Let’s consider the case where op
is the binary operation of adding two numbers together. In this case, I
is 0
(zero), since any number plus zero gives you the original number.
Now let’s consider the case where op
is the binary operation of multiplying two numbers together. Here, I
is 1
(one), since any number times one gives you the original number.
And are you seeing my point, here? When those ontology guys asked me if it was ok to use the term “unit” to refer to “nothing,” it must have had something to do with monoids. Unit
must be related to some theoretical notion of identity, and in the context of multiplication, the notion of identity is indeed… one. Hence the term unit?
Anyway, let’s return to Scala’s type system…
7. Unit
and Nothing
So Scala has this thing called Unit
. It’s a type in the language used in situations where a function actually returns nothing.
In some sense Unit
means nothing. Personally, I would have chosen Nothing
rather than Unit
as way to say …you know… “nothing”. But it turns out that the type Nothing
is used in Scala for something else.
Nothing
is one of the so-called bottom types in the language. It is a subtype of every other type in the language. And rather than denoting “nothing” as the term suggests, Nothing
actually denotes “never”. When a function is intentionally designed never to return you specify its return type as Nothing
. Personally, I would have chosen …you know… Never
to capture this. But remember, I am not a computer scientist.
Using the same pseudocode as above, you might write such a function as follows.
function Event_Loop() returns Nothing is begin while(true) begin ...event processing here... end end
You can see from that never-terminating loop that the function never returns, it just loops around again and again, processing events ad infinitum. (You have to admit, return Never
would have fit this situation really well.)
Admittedly, all this one is nothing and nothing is never is… well, confusing. But frankly, once you get passed this minor hurdle, the details of the Scala type system are frankly stunning.
But that, dear reader, is a topic for another day.
Mercury Rising
…and in the National Gallery of Art, we saw Mercury rising:
White House Garden Tour
Did I tell you about the garden tour?
What garden tour?
I guess I didn’t tell you. Do you want to know about it?
Actually, I…
We had gone to Washington, D.C. to visit friends who had moved there. We went to see Melissa and Carlyle and Trudy’s friend Karen who was following her boss who had taken a cabinet secretary position. And it turned out that the White House liaison in the agency was giving out tickets to the fall Whitehouse garden tour.
…but I…
We felt so… connected. How many degrees of separation from the President would that have been. Certainly only a few. We were tickled to have tickets. To be in the know.
…I see.
So we met Karen and took the metro to the White House. And when we got there, we should have known something was not quite right.
…not quite right?
Well not not quite right. I mean, not wrong. But it wasn’t as we thought. You see we had these invitations and were feeling all smug, and then we got there, and there was a very, very long line. This was not exactly a small affair. In fact, there were two lines with Park Service rangers asking if we had 1:00 or 1:30 invitations and directing us to the 1:30 line.
…that’s a shame.
But not really a shame, because the line move quickly and the people were generally in a good mood and although it was chilly in the shade, the sky was blue and the sun was shining…
…of course, blue sky and shining sun.
…and the grass was green.
..right.
So we eventually got in and gazed in earnest admiration at the various trees planted by the various presidents over the years. And we filed by the south portico.
…very nice.
And we peered into The Rose Garden and gawked at the empty podium there.
I mean this is really six degrees of separation stuff, right? What, the day before he must have been out there talking to…
…to someone.
Precisely. So anyway, we walked past the White House and admired the west side of the south lawn. There were more trees there, …
…more trees.
and we could see the Old Executive Office Building just nearby. (I’ve always been a pushover for that building.)
…of course.
Did you know that from the South Lawn you look past a fountain across the Ellipse to the Washington Monument?
…I think I knew that.
And that from there you look out across the Tidal Basic at the Jefferson Memorial?
…I didn’t…
I didn’t either. And so I must confess that this is the reason I wanted to tell you this. I wanted to tell you what a spectacular view that was, standing there beside the lush green grass of the White House South Lawn on a sunny, cloudless fall day with the White House itself behind us
gazing to the south at the Washington Monument wrapped in protective scaffolding ever since the earthquake, gazing at the Jefferson Memorial
… thru the Jefferson Memorial, because we could see daylight on the other side.
As I said, it was a spectacular view.
…very nice.
And there was the Marine Corps band playing at the foot of the hill. And there was the vegetable garden. But here’s what I really wanted to tell you.
…oh.
When we left the South Lawn and began walking around the Ellipse to the Mall, we passed a couple people who were distributing some kind of flyers. They looked like students. They had badges hanging from their necks, and they had that youthful college intern look.
…ah.
And as we got up to them, they held out the flyers to us and asked us, “Do you need tickets to the garden tour?”
…um.
The three of us looked at each other. These two interns were holding thick stacks of Fall White House Garden Tour invitations. The same select invitations that got us in. All of the sudden, we didn’t feel quite so … connected.
But whatever. We had a good time, and it was a beautiful day. We left the White House behind us and headed toward the National Gallery of Art.
…which can be a story for some other time, right?
Sure.
Fairness
Ok, so this isn’t fair.
We’re up at 5:45am. Before the rising of the sun. Before the rising of the dogs. We’re out of the house by 6:32. To go running. Six miles for the fair and industrious Trudy. Ten for me, although truth be told, the hills and progression miles took their toll and had me walking in spurts at the end so ten is not likely an accurate count. But you get the idea.
And then we’re out running errands. Acupuncture appointments. Baby gifts for Alex and Kim next door. Reflective running gear for those runs in the dark that will come next week and next and next. And although Trudy managed to sneak in a nap or two in the middle of the day, I didn’t. Concentrating as I was in front of the computer for a while on VirtualBox and Vagrant and Puppet and yum updates that are failing because nothing needs updating.
So at the end of the long day, I finally lay me down to sleep. But no. No sleep.
Wide eyes. Stevie Wonder bouncing thru my brain, because I had the temerity to actually play some music on the stereo yesterday (my brother would be proud) and Masterblaster was the last thing I played and my brain is evidently stuck in infinite replay mode.
No sleep. As Trudy breathes long in-and-out breaths, I’m thinking of SQL queries. And the hedge in the back that needs clipping. And the pergola that’s going to fall down any day now. And the irises that need to be dug up and clipped. And the two Bluebonnets that I saw sprouting next to the tomatoes that froze the other night before it got to be in the 80s today. And the compost piles that need to be consolidated. And wouldn’t it be nice to have different house numbers on the outside of the house under the light thrown down by our new sconces?
It isn’t fair.
Afternoon Break
1. No Sign Up
It was afternoon. The room was dark. I was starting at the computer screen. I’d been working on this query all day, and it wasn’t coming together.
In the hall, some people were talking. Something about coming up from downstairs. Something about not signing in. Something about a chair massage.
“What?” I said, turning around and looking at them. “We don’t have to sign in?”
I had seen the email about chair massages and signing up. But as with so much that comes into my inbox, it went in one ear and out the other, and I never did sign up.
“No,” Terri said. “Not many people signed up. They’re just standing around down there.”
“What room?”
“Harris.”
“You don’t have to tell me twice.”
I heard them laughing as I turned the corner.
2. In Harris
Harris was dark.
Was it too late? Had they already left? I pulled the frosted glass door open.
There was soft music playing somewhere in the front.
In a corner in the back, there was a massage chair with someone in it. The therapist looked up at me and smiled. I waved back.
In the front, there was a second chair with someone in it. And there was a third, empty chair and a woman in scrubs sitting next to it reading.
She heard me coming and stood up smiling.
“Are you ready?”
“I didn’t sign up.”
“That’s ok. Have a seat.”
3. Died And Gone to Heaven
I have heard of this before. Stories of software companies in the peak of the dot-com boom. Startups treating their employees to chair massages. I had a friend who left the space business to work at one of those companies. He used to tell us stories about those heady days.
But I missed those days, making the jump just as the bottom fell out. I missed the chair massages.
Until today.
Ten minutes. A perfect way to get that query out of my head.
Afterwards, as I was returning to the quiet and the darkness of our corner of the second floor, I passed thru the kitchen, and there on the counter were two big plates of fruit.
Apple slices. Pineapple chunks. Purple grapes. Big read strawberries. Sitting there on the counter. There for the taking. After a chair massage.
How about that? I must have died and gone to heaven.
Eight Miles Along the Potomac
1. Out
It was 41 degrees, not cold by Washington, D.C. standards for October but cold for a Texan. So although I was wearing running shorts, I also had a jacket, an ear band and gloves to keep my fingers warm.
This weekend, we were supposed to run eight. I had originally planned to run up Rock Creek where Trudy and I had ridden bikes last time we were here. But on Friday Amanda had plotted what seemed a better route that went south instead of north.
I crossed Rock Creek on the P Street bridge and took a sometimes-brick, sometimes dirt trail along the top of the bluff overlooking the creek and the parkway. I crossed Pennsylvania Avenue and ran to the mouth of the creek near Thompson Boat Center where the trail turns south along the Potomac.
I ran past the Watergate, past Kennedy Center, down the marble steps between the Lincoln Memorial and the river. I ran past the Tidal Basin, under the Arlington Memorial Bridge and followed Ohio Drive under the spaghetti of 14th Street and US-1 and Interstate-395. And I finally ran along the western edge of East Potomac Park under the Cherry Trees that will be blooming six months from now.
I ran almost to Hains Point — not quite, but almost, because time was ticking away and I needed to turn back.
2. And Back
On the return, I stopped at the Jefferson Memorial. Of all the times I have come to this town, I have never been here.
I ran up the steps and walked around throngs of tourists and sat inside on the marble benches along the circumference and gazed up at Thomas Jefferson standing under that white dome surrounded by those great ionic columns.
I am not an advocate for frequent changes in laws and constitutions, but laws and institutions must go hand in hand with the progress of the human mind. As that becomes more developed, more enlightened, as new discoveries are made, new truths discovered and manners and opinions change, with the change of circumstances, institutions must advance also to keep pace with the times.
And after sitting there, I was late.
Around the tourists. Back down the steps. Beside a long line of people in purple walking to end Alzheimer’s. Back up along the Potomac with the wind at my back. Texting Trudy on my progress, knowing that she might be wondering if I was going to finish in time to meet her and Karen for lunch.
@jeff memorial
@lin mem
@kennedy ctr
@watergate
@rock ck pk
@P and 23rd
And finally @home.
By Washington, D.C. standards, it might not have been cold that morning. And for a serious runner, those eight miles would have been nothing. But let me tell you, the steaming, hot shower felt mighty fine.
After the Fifth
We went for lunch a few blocks down the street from the main office. I was happy to have friends to eat with while I was visiting. We sat in a sunny spot in a glassy corner of the restaurant. After the meal, one of them started telling a story.
“I went to a Giants game once,” he said.
I’m not sure what in our conversation led him to say this, It must have made sense at the time, but it escapes me now. In any event, with an opening like that, I pushed back into my seat to listen.
It was the fifth inning.
His story seemed to have taken place some time ago, but he remembered for heaven’s sake what inning it was. And he remembered who the Giants were playing. Heck, I’m not even sure as I sit here whether it was indeed the Giants or somebody else, but he not only remembered that detail and what inning it was, but he also remembered the score.
The Giants were ahead 4 to 1.
He told us that he had been drinking a beer, holding the can in his left hand. And he told us how now he had to keep holding it that way, not switching hands or changing anything else until the end of the game lest it jinx the lead and cost the team the game.
But you see, it was the fifth inning with plenty of time remaining. So he was stuck there in the stands for the second half of the game holding his beer in his left hand. Which he did. And sure enough the Giants won.
Later as he was taking the subway home, he felt a tap on his shoulder and turned around. It was a policeman who pointed to the beer can my friend was still holding.
You see, from that moment in the fifth inning he had not let go of it. Without even realizing it, he had left the ballpark and started home with it glued to his hand with only a tiny amount of beer remaining. And now here he was. And the tiny amount in that open container was enough for the policeman to start writing a ticket.
Oh come on, my friend said. This is kinda like… kinda like… you know when you come home from the gym and realize that you’ve still got one of their towels.
The policeman looked up and said, Oh I hate that. It always happens to me!
You see? You see!? This is just like that, my friend said.
But I’m still writing you the ticket.
And that was that. End of story.
Pink and Chartreuse Socks
1. Jonnie
A woman walked away from gate 10. She held a leash, and a pudgy, white, puggish-bullish dog was walking trotting along happily with her. I looked over with at the woman standing next to me. She raised her eyebrows.
“I didn’t know you could do that,” she said.
“They were at security when we went thru,” I said. “And the dog was loose, just walking around.”
The woman raised her eyebrows higher, and we began to chat about minor, miscellaneous things, the kind of treading-water conversation you have with someone standing next to you when you stand beside the designated stanchions waiting to board a Southwest Airlines flight. Then they began boarding numbers B-31 thru -60.
As we walked down the gangway, I noticed the woman’s shoes.
“Are you running?” I asked. This was the weekend of the Marine Corps Marathon, and we were flying to Washington, D.C.
She looked back at me and smiled. “Yes! Are you?”
“No,” I said, “but we’ll be there cheering. What will you be wearing? Anything we can keep a lookout for?”
“Pink pressure socks,” she said. “Up to my knees.”
“I’m David, what’s your name?”
“Jonnie,” she said.
“We’ll be looking for you, Jonnie. Good luck!”
2. Cass
I walked to the back of the plane hoping to find two seats together.
“May I sit here,” I asked a woman seated along the aisle in one of the rows near the back. I pointed to the two seats next to her.
She smiled, nodded and stood up.
“I’m going to try to save a seat for my wife who’s further back,” I confessed. The woman smiled as she sat back down.
You see, the fair and industrious Trudy had arranged every detail of this trip, including checking in ahead of time, but our boarding passes were not consecutive. She told me she checked me in first to get the better boarding number, but she warned me that I’d have to try to save a seat for her.
I watched nervously as passengers continued to walked towards the back of the plane. And then there before me was Trudy.
“It’s my wife!” I said to the woman, relieved that I didn’t have to tell anyone they couldn’t have that seat.
The woman got up. Trudy sat down. We buckled ourselves in and leaned back in the seats.
“I met a woman who is running on Sunday,” I said to Trudy.
The woman in the aisle seat heard this and leaned forward. “Are you two running Sunday?”
“No,” said Trudy. “We’re visiting a friend.”
“But we’ll be out there on Sunday cheering,” I added. “What will you be wearing? Anything we can keep a lookout for?”
She smiled and said, “Pink or chartreuse socks.”
“I’m Trudy.”
“And I’m David.”
“I’m Cass,” the woman said.
The plane passed 10,000 feet, and they told us we could turn on our electronic devices. I pulled out my laptop. Trudy read a book. And Cass turned the pages in a runner’s magazine.
3. Postscript
On the morning of the marathon, Trudy made coffee and we walked down the hill to Rock Creek Park. We found the perfect spot along the route somewhere between mile 6 and 7. We watched the wheelchairs and then the first men and then the first women go by. We watched and cheered as the stream of runners grew to a pack. We watched them run up the hill, and we watched them as they ran down the other side of the street.
We cheered and clapped next to a stone wall near the bend in the creek with a perfect view of the runners coming around a corner and under an arching span of the P Street bridge and disappearing around another bed under an arching space of the Q Street bridge.
And although we cheered and clapped from the leaders until the 4:30 pace team passed us on their way up the hill, we never did spot Jonnie or Cass, which is of course no surprise. Still, we did see many pink and chartreuse socks.
© jumpingfish by David Hasan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License