Haskell: Language Rascal

By Gage Swenson,

Car codin

PokitDok is a cutting-edge product, powered by engineers with a knack for stringing together cutting-edge tech. It's one of many reasons why PokitDok is such a great company. If you talk to any of our scientists, you will quickly find that all of them are an expert at something state of the art.

My name is Gage. I am the newest intern of the PokitDok team, and I am passionate about revolutionary languages. I have been interested in computer languages since 6th grade, when I first saw them being used to modify video games. As I progressed, I marveled at the possibilities and options I had when designing and writing software. As time went by, my interest in computer languages grew, and I have since used and studied more than five programming languages.

My first task at PokitDok was to get acquainted with the PokitDok Platform API by writing an API client in a language of my choice. API clients allow software developers to easily implement the features of PokitDok in their own programs. We already have clients for Python, Ruby, C#, and many others. I chose to write a client in Haskell.

What is Haskell?

Haskell is a revolution in high level programming. High level programming allows software developers to write code without a lot of understanding of the underlying hardware.

Languages have evolved from low to high level. Most programming languages are typically written in and based off of C, an old, low-level, and widely-used language that allows people to write powerful software without having to battle their CPU. Python, our powerhouse, implements all of the the best features of the best languages into one sweet, easy to use package, and that's why we love it.

Haskell is a different story. Like many languages, it is feature rich and minimalistic. Unlike most languages, many of its features are based off of higher level math concepts. If you've heard of lambda calculus, category theory, or type theory, you will love Haskell! If not, you're going to learn many higher order concepts through using it.

Instead of starting from the ground level of C and working up towards something more friendly, Haskell starts from from the top level of mathematics and boils down to concrete operations. It is difficult for seasoned programmers to grasp because it is so radically different, but it is a very easy language for a mathematician to learn.

For example, take the following factorial programs, one in Java, one in Python, and one in Haskell. Which is easiest to read?

Java example:

Python example:

Haskell example:

You'll see right away that Haskell looks fresh and different, because it does not use C style syntax. But that's not the only cool thing that's going on here. Most of the words and characters in the python and Java examples are hard-coded into the language. Most of the characters and symbols in the Haskell version (except main and =) are not inherent in the language but are implementations of its features. Most of the functions you see can be removed from the language by not importing prelude, its base package.

In this regard, Haskell is more of a metalanguage. It allows programmers to write their own rules and regulations for functions and create their own data types that are as native as its own. It doesn't force people to code one way, so long as their code is strongly typed (every function yielding the same type of result).

Haskell has three other ground breaking features that can't fit into the scope of this article.

  • Purity — functions always return the same thing given the same arguments. This is escaped by the IO monad, allowing for unsafe data handling in pure code. (Monads are a whole other thing - read about them here)
  • Algebraic Data Types — creates datatypes on the fly, given other datatypes as arguments. can be recursively defined.
  • Laziness — nothing is evaluated until it is executed. This is a big one.

Most languages are strict, which means that things need to be evaluated before they are defined. In Haskell, things can be defined without being evaluated thanks to strong typing. For example, in Haskell, I can create an infinite list of numbers:

Where ints is a list, its first element is one, and its next element is the previous element plus one. This compiles in Haskell. You can then use this list by having it strictly evaluate the list, one element at a time.

Haskell has its drawbacks. It's experimental, theoretic, and rigid at times. It adds many features to programming that other languages don't have, and it strips out the most rudimentary features of other languages. It also has its perks: when it compiles, it runs, and it only throws exceptions when you or a library tell it to. Haskell doesn't serve to solve any language's problems. It serves as a new way of coming up with solutions. Bulletproof JavaScript applications can be created by compiling Haskell to JavaScript. Concurrency can be natively implemented in Haskell since it is not confined to line by line execution or state variables.

Haskell is cutting-edge. It takes a bold approach to computer programming using mathematics. That is why we at PokitDok love it.

If you're curious, be sure to check out the client library!


The opinions expressed in this blog are of the authors and not of PokitDok's. The posts on this blog are for information only, and are not intended to substitute for a doctor-patient or other healthcare professional-patient relationship nor do they constitute medical or healthcare advice.

  Tags: Dev


  Comments: 3

  1. Very nice article! Just wanted to point out a small typo in the Haskell example:

    "getLine >> =" should be "getLine >>=" without the extra space. Also, remember to include "show" before "putStrLn" to convert the numeric result to a string (I still forget this all the time).

    In fact, the code can be streamlined a bit by using "do" notation--not assuming you don't know this, just including in case other readers are curious :-).

    main = putStrLn "Factorial: " >>
    getLine >>= putStrLn . show . factorial . read

    This can also be written as:

    main = do
    putStrLn "Factorial: "
    num <- getLine
    putStrLn $ show $ factorial $ read num

    Alternatively, you can use "fmap". "fmap" will apply the functions "factorial . read" to the result of "getLine".

    main = do
    putStrLn "Factorial: "
    fmap (factorial . read) getLine

    Keep up the great work! It's outstanding that you're learning/using Haskell at such an early age!

    • I take the blame for that extra space, Chris! I must have introduced that while formatting the code for display on the blog. Fixed!

  2. Pretty impressive! I'm a fan!

Your feedback