Functional Programming Rocks

One of the mathematical properties of a function is that given the same input values it will yield the sam output value every time. In addition, there will be one unique value for every set of input values. This property is called referential transparency. A consequence of referential transparency is that when you compute the value of a function for a given set of input values, you can make a note of that output value and the input values (called memoizing) and the next time you want to know the value for that set of input values you can look it up. That is usually less work than computing the value every time you need it. Some functional languages are aware of this property and automatically memoize calls to functions that will benefit from it.

Another feature of functional languages is that they treat functions as first class elements. That means that functions can be passed as arguments to other functions. This is useful in creating higher level behaviors. For example, we can create a function called sort that accepts a function that compares two elements. Then, by changing the comparison function we can sort by ascending values with on comparison function, sort by descending values with a different comparison function, and so forth. We can even sort by several different attributes if you are sorting records. Basically your options are only limited by your imagination.

There is a technique that is often used in functional languages. It is called currying and is named after the mathematician Haskell Curry. When you create a curried function you define a function that associates fixed values to some of the parameters of a function. Then when the remaining parameters are supplied it returns the same value as would have been returned if all the parameters had been supplied at once. For example, you might have a function called “add” that takes the arguments “a” and “b” and returns the sum of “a” and “b”. You might notice that you often add 2 to other numbers. You could create a curried function “add2” that takes a single parameter “a”. “add2” adds two to “a” and returns the sum. This might sound like an odd way to do this but it gives the compiler opportunities to optimize the curried function. It also makes your code more concise and easier to read.

There are other advantages to functional programming. I’ll write about them in future blog posts. But I hope this post has piqued your interest enough to inspire you to look into functional programming. There are a number of different languages that offer functional features. If you are a fan of Java, you might check out Scala or Groovy. If you are a Python programmer, give Julia a look. I have been looking into Elm of late. It is an excellent introduction to functional programming.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

The Elm Programming Language

Elm is an impressive programming language. It has been around for five years. It is one of the group of recent languages that compile to Javascript. As such, it has been primarily used to develop web applications. But that is selling it short. It is more innovative than most of the myriad other new languages that have been introduced in the last five years and deserves far wider attention than it has thus far garnered.

First of all, Elm is a statically typed, purely functional language. It treats all values as immutable and has a module system that enforces semantic versioning. Function invocation is accomplished by writing the function name followed by the arguments of the function separated by spaces. There are no parenthesis around the arguments to a function or commas between them. Parenthesis are reserved for forcing grouping of elements.

Elm looks clean on the page. It is designed for creating reactive web pages and consequently has the Model, View, Controller paradigm built into the basic structure of its code. It calls the Controller function ‘update’ though which actually makes more sense. It has incredibly informative and helpful error messages. It enforces good program design at compile time, consequently there are virtually no run time exceptions to deal with. Any such exceptions that do arise come from the fact that it tightly integrates with Javascript, HTML5, and CSS.

I’ve looked for books on Elm but I have only found one or two. The best one is the Elm Tutorial which is available for free online and is a compendium of most of the other online documentation. The language is small and concise. There are a number of examples available to help the neophyte get up and writing their web applications in short order.

Elm leverages the Node.js ecosystem to do a lot of its heavy lifting. Consequently, it is easy to use the Electron package to develop desktop applications in Elm. What is left facing the developer is a clean, easy to maintain syntax that encourages expressiveness while rejecting unnecessary boiler plate. Although the language is statically typed, type declarations are optional. Explicit type declarations are useful to improve performance and sometimes to allow more expressive interface definitions though.

As far as expressing web pages in Elm, it is far easier to read than HTML. I plan to do some development in Elm and will report back when I have more experience with it under my belt. In the mean time, you can check it out interactively on the web at http://elm-lang.org/.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Etude

The heat was oppressive. The humidity was high. The air was still. The sun beat down brutally. It was August in the south but it was more extreme than he remembered it being. There was rain this year. That was better than the drought that had stretch until well after Christmas last year.

He dashed into the bookstore and breathed the blessed cool of the air conditioning. He made a bee line for the cafe and ordered a large iced coffee, black. He carried the drink to a table at the back of the cafe area and claimed a table. He took his laptop out of his case and started to write. There was hustle and bustle around him but it was unexpectedly soothing.

He limbered up with an entry in his journal. He used the opportunity to sketch out his plans for the rest of the afternoon. He would get fifteen hundred words in on the story he was writing. He wasn’t sure how long it was going to be yet. He was letting the story dictate its own parameters. Then he had a piece that he needed to edit. It had been sitting there for a couple of weeks while he let his subconscious ponder on it.

Writing was like cooking. If you tried to write according to a formula that you read in some book, the words came out dry and without spice. You had to let yourself live with a piece after you wrote it. Your conscious mind would move on to other things but your subconscious would continue to process it. When you got back around to it and reread what you had written it was often apparent what you needed to do to it to fix it.

A friend stopped to say hi. I hadn’t seen her in a while. We talked for a minute. She asked what I was doing. I told her I was recreating myself as a writer. She laughed and said she had tried to write and had given up after a couple of months. I smiled and said I understood. But on the inside I judged her. You can’t expect to develop the skills of a writer in a couple of months. I bet she had spent more time staring at a blank page than she had writing.

I remember that phase. I wanted to be a writer but I didn’t know what to say. I discovered that it didn’t really matter what you said. You just had to sit down and say something. You had to plant your butt in a chair and write whatever comes to mind until it is second nature. When you no longer think about the process of transferring your ideas from your mind to the paper, then you are ready to start guiding your writing into specific places.

She said her goodbyes and moved back into the forest of shelves at the back of the store. I finished my journal entry and started my days work. I mentally adjusted my word count goal up to two thousand words.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Summer Stock Theater

Once upon a time there was a theater on a lake. Every night except Monday night from Memorial Day to Labor Day a company of players put on a play in that theater. Sometimes there was a full house there to see the play. Other times there were only two or three people. It felt strange when a company of thirty or forty people put on a show for an audience so small. But they were dedicated thespians and they considered it an opportunity to demonstrate their professionalism and besides, they could use the rehearsal.

Every night after the show when the audience had gone and the players had changed out of their costumes and washed off their makeup. After the crew had swept the stage and put up the properties. The director, or sometimes the stage manager in his stead, would give notes to the cast and crew about the performance.

Sometimes, if there was something that needed some extra work, he would call a special rehearsal for the next afternoon before the show. Sometimes, when the cast and crew got out of line, as they were sometimes known to do, the stage manager would have to fine the offenders, according to their offense.

For example, their was one scene in the play where four of the actors, dressed in fantastic garb and supposedly representing the rampant rivers of the region, plagued the poor farmer whose bottom land was subject to flooding, at the behest of the spirit of nature that directed them. One night, the actors playing the rivers hid squirt bottles in their fanciful costumes and drenched the actor playing the farmer.

Everyone, including the actor playing the farmer, thought it was funny. Even, I suppose, the stage manager. But what it wasn’t was professional. The people in the audience paid to see a professional show, not a sophomoric comedy. Consequently the actors playing the rivers were fined. Not large fines, they weren’t paid that much in the first place. But fines large enough to insure that they would think twice before pulling a prank like that again.

To the eight year old boy that I was at that time, it seemed harsh punishment. To the adult that I am now, it seems a fair one. I miss those people. They were my extended family. I learned a lot about the ways of the adult world from them. Many of them are probably dead now. All of them are as old as I am or older.

The theater was torn down several years later. Now the memories of those magical times live on in the memories of the few of us that are left who lived through them. But the world is a better place for the art that we created.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Leading From the Rear

I remember a time when I was in high school. My father taught Speech, English, Theater, and other related subjects. He also usually produced the plays, one in the fall and one in the spring. Dad was what you might call strong willed and was noted for rubbing people, especially incompetent administrators, the wrong way. One way or another he had gotten crossways of the current principal of the school and to “punish” him, the principal asked one of the other English teachers to produce the spring play.

My dad was one of the best teachers I ever new except my mother but that’s another story. But he had carefully trained himself to be a Broadway stage manager. His teaching credentials were a concession to his father who had no confidence in his ability to make a living as a stage manager. When my father graduated from college he presented my grandfather with his diploma and said, “There’s my teaching degree. Just like you wanted.” He was then promptly drafted into the Army. But not before he married my mother and got her pregnant with me.

He spent his time in the Army in Germany, a good place to be considering the Korean War was winding down in South East Asia. He was assigned to a training company but was almost immediately sent on a temporary duty assignment to produce a variety show with talent pulled from the various units assigned to Europe. And what a show it was. I never saw it, of course but he often told stories about it as I was growing up.

The point I’m getting at is that producing a play is a challenging task. It isn’t something that just any English teacher can pull off. Especially not the one the principal assigned to produce the spring play. I consulted with dad to make sure that he wouldn’t take my participating in the spring play as disloyalty to him. He assured me he would not and encouraged me to go ahead.

So, having acted in plays and watched my dad produce them since the age of eight, I proceeded to manipulate the “faculty sponsor” of the play into producing the play I wanted to do, “Big Rock at Candy’s Mountain”, a comedy parody of Woodstock, complete with live rock music. I designed the set and lead the crew that built it. I pulled together a band that cleverly served as three different bands as each of the guitarists took turns leading the band under a different name. I played one of those musicians. It was a lot of fun. But it was successful because I knew how to produce a play and lead a cast and crew. In other words, in spite of the “faculty sponsor”.

Dad got back in the good graces of the administration the next year and went on to produce many plays at the high school. The other English teacher was more than happy to let him do it. And I went on to play a gunfighter in western theme parks during my summer breaks in college.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Of Dreams and Dreaming

I read an article that cited a study that asserted that people that slept more than nine hours a night were subject to more nightmares. I think this study may be found lacking. My personal experience is that when I sleep more than nine hours in a night I remember my dreams better. They are sometimes frustration dreams but seldom what I would call nightmares. How do the authors of the study know that the people that were reporting nightmares when they got over nine hours of sleep weren’t having them when they got less than nine hours of sleep but just were less able to remember what they dreamed.

I find that any change to my sleeping routine has a noticeable effect on the quality of my rest. Not all of these differences are bad. When I sleep longer than my usual seven hours sleep I am definitely more rested to a point. At ten hours I typically start getting restless and wake up.

It also matters whether I have been getting eight hours of sleep consistently for several nights in a row or only six or seven hours. Tiredness seems to be cumulative for me. If I get too little sleep for four or five days in a row, I get drowsy during the day. When I have gotten between eight and nine hours of sleep, I am alert and aware of my environment.

I have wanted to try lucid dreaming, a practice by which you take conscious control of your dream state. I have had little success with it thus far though. The closest that I have come to it though is the time right before I wake up when I’ve had nine or more hours of sleep.

I’ve also had a good bit of success with autosuggestion. I go to sleep thinking about when I want to wake up and I am usually pretty good at waking up right at the time that I had decided that I should wake.

I have often wanted to study hypnotism more closely. I have been hypnotized so I have experiential evidence that the phenomenon is real. I have tried to hypnotize people and found that either I don’t have the requisite tone of voice or none of my subjects took me seriously.

I have also wondered if we didn’t have more influence on things happening in the world around us than is commonly believed. I have plenty of episodic evidence to that effect but none of it s water tight. Unless and until I can repeatably demonstrate the phenomena, I will file it under wishful thinking.

I do believe Arthur C Clark’s third law, “Any sufficiently advanced technology is indistinguishable from magic.” It is why I make no distinction between Science Fiction and Fantasy.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Data Science Breeding Ground for GAI

We are drowning in data. All kinds of data, video streams, sensor data, weather satellite data, you name it. Much of this data is available on the internet. But knowing how to fetch this data is hardly useful unless you know how to process the data and tease new facts out of it. This is the age old problem of turning data into information.

We are collecting such immense amounts of data that we can no longer pour over all of it individually. We have to apply statistical methods to help us understand the trends, to recognize patterns, and make predictions based on the results of our analysis.

People that use computers to analyze this data glut are called Data Scientists. It is an interesting combination of skills. You need programming skills, mathematical skills, and communication skills. As progress in the field occurs we see various artificial intelligence techniques being applied, in particular machine learning.

Machine learning has been studied for over seventy years now. In recent years we have made vast strides, in part due to advances in processor horse power and distributed computing techniques. Much work has been done on so called deep learning which uses artificial neural networks to perform sophisticated tasks normally associated with human expertise.

Recently Facebook AI chatbots developed a private language that was unknown to the researchers. The machine was shut down. I am becoming more and more convinced that if we haven’t already seen the emergence of General Artificial Intelligence (GAI), it will not be long before we do. And it will be due, in large part, to the very sea of data available to a neophyte GAI.

I doubt it will know how it works. Do most people know how their brain works? But it will learn and when it does, it will figure out how to improve itself, much like human beings do. Only the GAI isn’t subject to forgetting like we are. It will consume Wikipedia like a candy bar and be on to analyzing the data feeds of our financial institutions and the signal intelligence collected by our intelligence community.

It is a scary thought and one that raises all kinds of interesting questions. For instance, how much privacy and freedom would you give up to keep a system like this in check? And, what’s to keep it in check in the first place? We’ve got a lot to think about and not much time to think about it. We are on the cusp of a new age on Earth and I’m afraid mankind may not be at the top of the intellectual heap. We need to start endearing ourselves to our mechanical overlords or at least make sure they don’t perceive us as a threat.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Pleased or Displeased?

My mother used to tell us about a game that she played when she was a little girl. It went like this. The first person says, “Pleased or displeased?” The next person says whether or not they are pleased. If they say, “Displeased,” the first person inquires, “What will it take to please you?” The second person then sets a task for one or more of the other people playing and they must do it. It is a silly variation on Simon Says, I suppose. Everyone gets a turn to answer the question in this game though.

I thought of this game because I am indeed displeased but I can’t for the life of me think of what it would take to please me. Part of my malaise has to do with the fact that it is Sunday afternoon. I have never liked Sunday afternoons. When I was little, my grandmother would make us go to church on Sunday night. I didn’t particularly like to go to church, on Sunday night or any other time for that matter.

Sunday night also meant there was school the next day. I liked school okay but I didn’t like the regimentation. I wanted to decide what I did and when. I also hated homework. I loved learning but I had no patience with rote exercises.

When I got older, Sunday night meant that I had work the next day. I dreaded work for much the same reasons that I dreaded school. I have been lucky enough to enjoy most of the jobs that I’ve had. The thing that I don’t like is that I have to follow someone else’s processes and schedule.

I wonder if I were to retire from my job and start writing for a living, if I would have the same attitude toward Sunday night. I would still have to do things that I don’t like very much. If I’m my own boss, I have to do all of the distasteful tasks, not just the few that I get assigned working for someone else.

On the other hand, I get all of the benefit of my efforts. That should count for something. And at my age I have the benefit of a retirement fund to underwrite the risky endeavor of being a freelance writer. If push comes to shove, I can find another job to supplement my income. I might even find one that takes advantage of my writing ability.

Okay. Go ahead. Someone ask me, “Pleased or displeased?”


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

I Heard It On The Internet, It Must Be True

The internet has changed the context in which we live our lives. We have practically instant access to any developments, political, social, literary, or artistic, as they occur. What’s more, the access is for the most part unfiltered. By that, I mean that there aren’t elite gate keepers that decide which items are of broad interest aren’t.

Before the internet, there were newspaper and magazine editors, TV producers, movie studios, art galleries, publishing houses, all of which exerted undue influence on what the world was going to hear about. These institutions still exist but because of the internet, they do not hold a monopoly on the flow of these ideas to the world.

Even the more totalitarian states in the world have found it hard to stem the flow of ideas that they consider objectionable or for other reasons worthy of censorship. It is hard to censor the internet. It was designed to survive nuclear war and tends to treat censorship as a transport failure around which it finds alternative routes.

When the internet was first made available to the general public many of us who had been aware of it in its use during the more restrictive research days predicted that it would be the downfall of all totalitarian states. That prediction turns out to have been naive. What has happened is that totalitarian states have learned to use the internet to spread their disinformation and propaganda.

It turns out that the ability to filter out content that you aren’t interested in has lead to a very unbalanced political situation. Instead of having healthy dialogs between parties with different perspectives, we have so-called bubbles that espouse positions based only on evidence favorable to those positions. There is now objective fact checking. The channels are saying what the recipients want to hear so nobody want to dig to deep and expose potentially counterfactual assertions.

If this were only happening on one side of an issue it wouldn’t be as bad a problem. But when all parties are only looking at the issues from their own perspective, it makes for divisiveness and lack of mutual understanding. I can understand all sides of an issue without having to agree with all or them. In fact, I can make a better decision regarding the issue the better that I understand all sides of it.

This situation is dangerous, to the extent that it may herald the end of our civilization. In any case, we have a lot to learn about listening to each other and getting along with people that have different opinions than we do. Our forefathers (and foremothers) understood this. Somehow we have become a generation in which many people have forgotten these important social protocols.

We have opened Pandora’s box. There is no going back. We can only go forward and hopefully learn from our mistakes. Technology holds great promise for the advancement of mankind but only if we use it wisely and thoughtfully.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.

Manifesto

It might be noon on the Sahara. It might be the heart of an Arctic blizzard. Whatever it is, it is daunting. I’m talking about the blank page that sits in front of me, taunting me to write something, anything. Insinuating that whatever I write will be pale and boring.

I’ve heard that I’m not the only one that sees this kind of thing when they look at a blank page. Nor are my fears singular. But I have the solution to this problem. I start to type. Soon the page isn’t blank any more. As I look back over my words, I realize that I have a choice. I can either leave the words that I’ve written or I can delete them. Which ever choice I make, it is better than having sat and stared at the blank page having written nothing.

Every word I write, every blog entry I post, every story that I tell, I get better at writing. Sometimes I immerse myself in it and lose myself in the flow of words. I enjoy every stroke of every key. I revel in the words that inch across the page. I may do that for a day or I may do it for a month. When I think to check my progress I am amazed.

My voice is beginning to shine through the prose. I see myself peeking out at myself from behind the words on the page. I am impressed at how cohesive my writing is and how smoothly it transitions from one word to the next, forming sentence after sentence, paragraph after paragraph. And if that isn’t enough, it actually is making sense. I am expressing my ideas in a coherent fashion. I am a writer.

Then I look at the disaster that is each of my prior attempts at novels. I am a little bit discouraged but there is a glimmer of hope. Deep in my chest I am convinced that there is a diamond in the manuscript just waiting for me to cut it and mount it and show it to the world in all it’s beauty.

I am scared that I will mess it up. But I will start from a backup. I will snapshot my work every day until I have managed to whip it into shape and I start looking for beta readers to help me figure out what works and what doesn’t. It is exhilarating to journey down this path for the first time. I suspect it will be ever so.

I think about my mother. She wanted to follow this path. I don’t know if it was depression, or the responsibility of two boys and a husband that had no concept of how to do anything more than the absolute minimum of domestic maintenance, leaving the bulk of the task to her. She wrote a little here and a little there but she never became the writer that she wanted to be. I reject that fate and claim my right to be a writer.


Sweet dreams, don’t forget to tell the ones you love that you love them, and most important of all, be kind.