Kids, Code, and Computer Science Magazine

Haskell

roland on Flickr

A balance of flexible and inflexible qualities make Haskell a fascinating programming language to learn and use.

First, the Haskell programming language is not named after Eddie Haskell, the sneaky double-dealing neighbor kid in the ancient TV sitcom, Leave It To Beaver.

Haskell is named after Haskell Brooks Curry, an American mathematician and logician. If you don't know, logicians create models to describe and define human reasoning, for example, problems in mathematics, computer science, and philosophy. Haskell’s main work was in combinatory logic, a notation designed to eliminate the need for variables in mathematical logic. Combinatory logic captures many key features of computation and, as a result, is useful in computer science. Haskell has three programming languages named after him: Haskell, Brooks, and Curry.

Haskell the language is built around functions, useful blocks of code that do specific tasks. They are called and used only when needed.

Another interesting feature of functional languages like Haskell: functions are treated as values like integers (numbers) and strings. You can add a function to another function the way you can add an integer to an integer, 1 + 1 or 35 + 53. Perhaps the best way to describe this quality is a spreadsheet: in a cell in the spreadsheet, you can add numbers as well as a combination of functions to work on numbers. For example, you might specify each number in cells 1-10 be added up as a sum. In Excel, at least, you also can use SUMIF to look for a pattern in cells 1-10 and, if the pattern is found, perform an action on any cells with the pattern.

What Makes Haskell Special?

Technically, Haskell is a general-purpose functional programming language with non-strict semantics and strong static typing. The primary control construct is the function. (Say that fast ten times!) Here's what it means:

  • Every language has a strategy to evaluate when to process the input arguments used in a call to a function. The simplest strategy is to evaluate the input arguments passed then run the function with the arguments. Non-strict semantics means the input arguments are not evaluated unless the arguments passed into the function are used to evaluate what is in the body of the function.
  • Programming languages have rules to assign properties — called a type — to the components of the language: variables, functions, expressions, and modules. A type is a general description of possible values the variable, function, expression, or module can store. Typing helps minimize bugs, for example, when a calculation uses a string ("house” or "cat”) instead of a number (2 or 3). Strong static typing evaluates the code before runtime, when the code is static and possibly as code is written.
  • The order in which statements, instructions and functions are evaluated and executed determines the results of any piece of code. Control constructs define the order of evaluation. Constructs use an initial keyword to flag the type of control structure used. Initial keywords might be "if” or "do” or "loop” while final keywords might be "end if” or "enddo” or "end loop”. Instead of a final keyword, Haskell uses indentation level (tabs) or curly brackets, or a mix, to indicate the end of a control structure.

Perhaps what makes Haskell special is how coders have to think when they use the language. Functional programming languages work in very different ways than imperative languages where the coder manages many low-level details of what happens in their code and when. While it is true all languages have things in common, it’s also true languages are mostly functional or mostly imperative, the way people are mostly right handed or left handed. Except functional programming languages require a different way of thinking about software as you code.

Other features that make Haskell interesting:

  • Strong data typing (evaluating properties of all inputs into a function) is combined with polymorphism; a function to sort numbers also can be used to sort strings of text. In some languages, you would have to code two or more functions, one for each data type.
  • Lazy evaluation (one of my favorite coding terms!) allows the result of one function/task to be handed to another function/task on the same line of code. For example, the command can search a file for all instances of a string then pass the results to be printed to the computer screen. Functions that can take other functions as arguments or return them as results also are called higher order functions.
  • No side effects. In other languages, code can affect the state of the computer and application, for example, writing to a file. Haskell strictly limits these side effects which, in turn, makes Haskell applications less prone to errors.
  • Haskell uses monads, a structure that works like an assembly line where every stop on the line performs a different task. This allows Haskell to separate side effects as a distinct activity apart from any function, for example, logging any errors as a function performs tasks on its data inputs.

Building from small bits of code, each bit tightly contained and testable.

How is Haskell Used?

As a functional programming language, Haskell has benefits like shorter development time, cleaner code, and high reliability. The tight control of side effects also eliminates many unforeseen interactions within a code base. These features are especially of interest to companies who must build software with high fault tolerances, for example, defense industries, finance, telecommunications, and aerospace.

However, Haskell also is used in web startups where functional programming might work better than imperative programming. Apparently Facebook, Google, NVIDIA, and other companies use Haskell to build internal tools used in their software development and IT environments. Even a lawn mower manufacturer in Kansas uses Haskell to build and distribute their mowers. And the New York Times recently used Haskell to build an image processing tool for the 2013 New York Fashion week.

The main Haskell website also has links to university courses, as well as research groups.

Learn More

Try Haskell

http://tryhaskell.org/

Haskell

http://www.haskell.org/haskellwiki/Introduction
http://www.haskell.org/haskellwiki/Why_Haskell_matters
http://www.haskell.org/haskellwiki/Functional_programming
http://www.haskell.org/haskellwiki/Category:Theoretical_foundations
http://www.haskell.org/haskellwiki/Lambda_calculus
http://www.haskell.org/haskellwiki/Haskell_in_industry
http://www.haskell.org/haskellwiki/Haskell_in_research
http://www.haskell.org/haskellwiki/Haskell_in_education

Haskell Brooks Curry

http://en.wikipedia.org/wiki/Haskell_Curry

Combinatory Logic

http://en.wikipedia.org/wiki/Combinatory_logic

Monads

http://en.wikipedia.org/wiki/Monad_%28functional_programming%29

Functional Programming and Imperative Programming

https://en.wikipedia.org/wiki/Functional_programming
https://en.wikipedia.org/wiki/Declarative_programming
https://en.wikipedia.org/wiki/Imperative_language

Side Effects

https://en.wikipedia.org/wiki/Side_effect_%28computer_science%29

Also In The November 2013 Issue

My Adventures with Raspberry Pi

Open source hardware geared towards artists, hobbyists, designers, and students, is a viable and far less expensive alternative to build your own computers.

Beth Rosenberg Talks How Tech Kids Unlimited Helps Kids Who Learn Differently

With a wave of kids with special needs graduating high school, how can technology help them with resumes, college, jobs, and careers?

Stop Words

A clever technique to speed up database searches also is an interesting concept.

More Fun with Raspberry Pi

Here are some videos, and links to even more videos, to learn how to use your Raspberry Pi and have all kinds of fun with Pi projects.

My goal wasn’t to make a ton of money. It was to build good computers.

News Wire Stories for November 2013

Interesting stories about computer science, software programming, and technology for the month of October 2013. More stories can be found at the Software Programming and Computer Science News Wire link at the top of every page of this site.

Bubble Sorts

With a bubble sort, numbers sort themselves as they bubble to the left of a group of numbers. Here's a fun catchy video to explain.

The 7 Bridges of Königsberg

This month's math puzzle dates back to 1735 when it was first solved by Leonhard Euler, a Swiss mathematician and physicist.

Pair Programming

From the start of computing history, people have tried to optimize the software programming process. This includes having two coders work together to code software.

Learn More Links for November 2013

Links from the bottom of all the November 2013 articles, collected in one place for you to print, share, or bookmark.

Icon-itis

The release this fall of Apple's iOS7 operating system is a great opportunity to explore the history of computer interface design.

Functions

Managing inputs and outputs is a key problem programming languages face. Here's how a few languages use functions to manage and transform data.