The Occam.fi Technical Series: On Building with Haskell

Occam_PR
Occam.fi
Published in
7 min readAug 6, 2021

This post is the fifth and final in Occam.fi’s technical series. We will be giving a rundown on Haskell’s history before its introduction to the crypto space, and discover the current languages that we’re able to code blockchains and their DApps in.

We will also explore why Haskell made sense for Cardano and make some conjectures based on a growing body of experience from people pioneering the future of Haskell with DApps and Cardano Native Token protocols.

As we are only a few weeks away from one of the most important hard fork events in the history of Cardano, it’s important that we all understand how Haskell performs a supremely important role in the Cardano ecosystem. So, let’s start with a history of Haskell!

Haskell, a Quick History

Haskell was born out of the 1985 release of ‘Miranda’, a lazy purely functional programming language. Following its release, there grew to be almost a dozen languages similar in scope to Miranda and by 1987, a conference on Functional Languages pushed for the consolidation of all the functional languages into one common standard, bringing about the inception of Haskell.

Following that conference, Haskell 1.0 to 1.4 were released featuring type classes and thus type-safe operator overloading. Type classes can best be understood as code that specifies a set of functions or constant names alongside their respective types, that must exist for every type of said class.

Additionally, this allowed for the development of operator overloading which allows operators, say addition and subtraction, to have different use cases depending on the arguments passed to them. Type classes, combined with operator overloading were to be the principal innovations of the initial versions of Haskell and provided a solid foundation for the developer community to iterate and improve upon.

Haskell would then be further iterated upon with the development of Haskell 98 and then Haskell 2010. The former was officially published as “The Haskell 98 Report” and was intended to be a stable, lightweight, and easily portable version of Haskell. Haskell 98 featured a standard library to encourage teaching and to act as the starting point for future extensions and variants of the language. The latter version of Haskell was an ‘incremental update’ to Haskell 98, and incorporated a variety of smaller features that had been developed over the years following the release of Haskell 98. Haskell 2010 was intended to act as the first in a series of potentially yearly updates to Haskell to continue to refine it and commercialize its use.

Though certainly a language with very old origins, Haskell has gone through multiple iterations since ‘Haskell 1.0’ in 1987, and now finds its use becoming more and more widespread, perhaps due in part to Cardano and the development of the Smart Contract language Plutus.

Moreover, IOHK has decided to sponsor the launch of the “Haskell Foundation” to “broaden the adoption of the Haskell language and support tooling, research, education, and libraries.”, this is on top of the developers and engineers at IOHK contributing significantly to the development of tje Glasgow Haskell Compiler, or ‘GHC’, Haskell’s compiler, finding and addressing Haskell bugs, contributing to multiple Haskell libraries and improving cross-compilation support.

Haskell is currently around 34 years old, but with the innovation that Cardano continues to bring it seems that Haskell will find itself holding a much more important position in the blockchain space at least, as we march on towards the 50 year anniversary in 2037.

Haskell in Industry

Though certainly not a well-known language by any stretch, Haskell is still widely used within the private sector industry, not just by academics and Cardano. Taking a glance at the Haskell wiki multiple things stand out at first glance. For example, it is very popular within the finance sector and is widely used for processing lots of data and for efficient algorithmic analysis.

With regards to the finance sector, you will find extremely large entities like Credit Suisse, Deutsche Bank, Bank of America Merrill Lynch, and Barclays Capital Quantitative Analytics Group using Haskell, among others.

Other companies like AT&T, BAE Systems, Facebook, Google, and Intel implement Haskell in a variety of use-cases — due in part to its high propensity to avoid bugs through functional programming. While Haskell itself may not be one of the languages that immediately comes to mind when one thinks of programming, it is nonetheless used around as a reliable and robust language capable of a diversity of execution areas.

Current Languages in Blockchain

Taking a look at the broader cryptocurrency ecosystem, the standard languages that projects are built on are the likes of C++, Javascript, Python, and at the moment the king of them all; Ethereum’s Solidity.

The key thing to understand about all of these languages is that for the most part, they’re all ‘imperative’ — meaning that their programs function as a sequence of statements that the computer needs to perform and more often than not have a global state that the program operates in. More on global state and Ethereum can be found here.

In contrast, with Haskell, functional programming is based on the movement of arguments and values through functions and transforming data. In this way, Haskell conceives computation as the evaluation of mathematical functions and avoids state and mutable data.

Although this may appear as a subtle difference between blockchains like Ethereum and Cardano, the implications are massive. Ethereum has experienced — and continues to experience — many of its woes, such as high gas fees and various bugs and errors, due to the ‘statefulness’ of the imperative language it is coded in.

Cardano on the other hand is coded in a functional language that removes the issue of bloated networks brought on by global states in favour of a blockchain built on solid mathematical functions that are readily reproducible and consistent. With Haskell, Cardano seeks to approach the challenge of scaling to potentially hundreds of millions of users around the world by developing a language that is much more efficient, faster, and safer as it moves towards handling larger and larger sums of capital.

Haskell and Cardano

Haskell is a bit of a walk off the beaten path, as being a functional programming language already knocks it off most people’s learning lists as mentioned previously. Add to this a relative lack of materials currently supporting the learning of the language (as compared to Java/C/C++/JS etc), and one may ask the question; “Why Haskell?”.

Charles Hoskinson compares Haskell to using “difficult surgical equipment, sure it’s difficult but at the same time you know the people who are qualified to use it are going to be very adept at it”.

People all throughout the industry have seen the many examples of projects being hacked, or people sending tokens to addresses that are unable to process and accept them and so a conscious choice to build with Haskell was made. The focus on academic rigor and provability of the code is inherent when writing with Haskell, and by its nature of being a rather niche language that advanced programmers and bright PhDs know and understand allows for a bit of a self-selecting talent pool which Cardano and its ecosystem are able to draw from. You’re much less likely to see someone with little knowledge of programming be able to spin up a Cardano project and potentially lose people’s money because of bugs, or scam them out of their money with their project’s intrinsic contract code.

Haskell’s functional uniqueness is instrumental for writing the huge amount of papers to come out of Cardano and IOHK, it being function-based with heavy a reliance on mathematics allows for much more formal verification than other languages. The academic research that Cardano funds is easily translatable into the crypto space because of Haskell, and allows it to be rapidly deployed and tested on the Cardano blockchain whereas, with other projects, breakthrough ideas might take longer to code and deploy.

When it comes down to it, Haskell is a perfect match for Cardano. Development on Haskell doesn’t mean rushing a product to market — instead, it is methodical, proof-based, offers very high developer certainly of execution, and it is built for the enterprise-level use-cases. Therefore, it needs to be robust and extremely accurate if Cardano and its ecosystem are going to handle billions and eventually trillions of dollars in assets down the road.

What This Means for DApps and Projects Building on Cardano

Ethereum’s Solidity is a lot like C/C++ in regards to syntax and structuring of the code which helps the onboarding of developers and companies looking to build DApps on the Ethereum blockchain, but this does pose a risk as quite a few people with minimal effort are able to potentially spin up projects that pose a risk for people within the ecosystem. While in theory, their code could work, once it’s deployed there are a variety of hacks and exploits that it could be targeted with and if the developers lack the sufficient skill to deal with it, it could and has resulted in large losses of money and capital.

That’s not to say that we have to gatekeep DApps, or that there needs to be some specific litmus test that projects need to go through. It’s just that one can rest easier at night knowing that projects built on Cardano involve more testing, security, and be potentially more optimal.

Furthermore, as we mentioned, the many large corporations that already use Haskell within their own companies validate the use of the language at scale. The intrinsic safety and eventuality of scaling to meet the demand of tens of millions of users is something all DApps on Cardano can look forward to when building their products on the Cardano blockchain.

While it may be more complex and require developers to be more thoughtful, in the end, it will help them produce a much more refined, safe, and efficient product — that is going to be able to grow alongside the network as we progress through the Alonzo era, into Basho, and eventually Voltaire. Cardano has always been about a thoughtful, methodical, and research-based approach to solve the blockchain trilemma, and the DApps building on top of it should align with that same ethos as well — this is made possible through Haskell.

--

--