1
1
mirror of https://github.com/thma/WhyHaskellMatters.git synced 2024-10-26 14:32:24 +03:00
In this article I try to explain why Haskell keeps being such an important language by presenting some of its most important and distinguishing features and detailing them with working code examples. The presentation aims to be self-contained and does no
Go to file
2020-03-21 18:30:42 +01:00
.github/workflows Update haskell.yml 2020-02-08 13:18:47 +01:00
img starting to work on article 2020-03-19 20:47:00 +01:00
src add some more code 2020-03-08 20:42:07 +01:00
test add some more code 2020-03-08 20:42:07 +01:00
.gitignore clean up 2020-03-05 21:42:18 +01:00
LICENSE Initial commit 2020-02-05 20:41:17 +01:00
package.yaml clean up 2020-03-05 17:26:30 +01:00
README.md work in progress 2020-03-21 18:30:42 +01:00
Setup.hs initial commit 2020-02-05 21:29:29 +01:00
stack.yaml clean up 2020-03-05 21:42:18 +01:00
WhyHaskellMatters.iml add some more code 2020-03-08 20:42:07 +01:00

Why Haskell Matters

This is a work in progress article.

Motivation

A strange development over time

In a talk on the Haskell journey from its beginnings in the 1980ies until 2017 Simon Peyton Jones speaks about the rather unusual life story of haskell.

First he shows a chart representing the typical life cycle of research languages. They are often created by a single researcher (who also is the single user) and most of them will be abandoned after just a few years:

most research languages

A more successful research language gains some interest in a larger community but will still not escape the "geek" zone and typically will die a bit slower:

successful research languages

Typical popular programming languages are adopted by large number of users and thus will quickly reach "the threshold of immortality". That is the base of existing code will grow so large that the language will be in use for decades:

successful research languages

In the next chart he rather jokingly depicts the sad fate of languages designed by committees. They simply never take of:

commitee languages

Finally he presents a chart for Haskell:

commitee languages

The development shown in this chart is rather unexpected and unusual: Haskell started as a research language and was designed by a committee so it should have been abandoned long before the millennium.

But instead it gained some momentum in the early years followed by a rather quiet phase during the decade of OO hype (Java was released in 1995). And then again we see a continuous growth of interest since about 2005.

Being used versus being discussed

Then Simon Peyton Jones points out another interesting characteristic of the reception of Haskell in recent years. In statics that rank programming languages by actual usage Haskell is typically not under the 30 most active languages. But in statistics that rather rank programming languages by the volume of discussions in social media Haskell typically scores much better (Often in the top ten).

So why is there so much talk about a language even if it is not one of the most active languages?

A very short answer might be: Haskell has a number of features that are clearly different from thiose of most other programming languages. Many of these features have proven to be powerful tools to solve basic problems of software development elegantly.

Therefore over time other programming languages have adapted parts of these concepts (e.g. pattern matching or type classes). In many discussions about such concepts the origin from Haskell is mentioned.

This then contributes to the fact that e.g. Typescript, Scale or Rust developers start to deal with Haskell.

A further essential point is that Haskell is still an experimental laboratory for research in areas such as compiler construction, programming languages, proofers, type systems etc. Haskell is also inevitably always a topic of discussion in the discussion about these approaches.

Haskell weist etliche Merkmale auf, die sich deutlich von den Konzepten der meisten anderen Programmiersprachen unterscheiden. Viele dieser Merkmale haben sich als mächtige Werkzeuge erwiesen, um einige grundlegende Probleme der Softwareentwicklung elegant zu lösen. Daher haben im Laufe der Zeit andere Programmiersprachen Teile dieser Konzepte adaptiert (z.B. Pattern Matching oder Typklassen). In vielen Diskussionen über solche Konzepte wird dann oft auf die Herkunft aus Haskell hingewiesen und auf Abweichungen in der Umsetzung der Konzepte eingegangen. Das trägt dann mit dazu bei, dass sich z.B. Typescript-, Skala- oder Rust- Entwickler anfangen sich mit Haskell zu beschäftigen.

Ein weiterer wesentlicher Punkt ist, dass Haskell immer noch ein Versuchslabor für Forschung in Bereichen wie Compilerbau, Programmiersprachen, Beweiser, Typsysteme usw. ist. Auch in der Diskussion über diese Ansätze wird zwangsläufig Haskell immer thematisiert.

So why is Haskell such a hot topic in the software development community?

Haskell doesn't solve different problems than other languages. But it solves them differently.

-- unknown author

  • Funktionen sind 1st class citizens (higher order functions, Funktionen könen neue Funktionen erzeugen und andere Funktionen als Argumente haben)

  • Abstraktion über Resource management und Abarbeitung (=> deklarativ)

  • Immutability ("Variables do not Vary")

  • Seiteneffekte müssen in Funktions signaturen explizit gemacht werden. D.H wenn keine Seiteneffekt angegeben ist, verhindert der Compiler, dass welche auftreten ! Damit lässt sich Seiteneffektfreie Programmierung realisieren ("Purity")

  • Evaluierung in Haskell ist "non-strict" (aka "lazy"). Damit lassen sich z.B. abzählbar unendliche Mengen (z.B. alle Primzahlen) sehr elegant beschreiben. Aber auch kontrollstrukturen lassen sich so selbst bauen (super für DSLs)

  • Static and Strong typing (Es gibt kein Casting)

  • Type Inferenz. Der Compiler kann die Typ-Signaturen von Funktionen selbst ermitteln. (Eine explizite Signatur ist aber möglich und oft auch sehr hilfreich für Doku und um Klarheit über Code zu gewinnen.)

  • Polymorphie (Z.B für "operator overloading", Generische Container Datentypen, etc. auf Basis von "TypKlassen")

  • Algebraische Datentypen (Summentypen + Produkttypen) AD helfen typische Fehler, di man von OO Polymorphie kenn zu vermeiden. Sie erlauben es, Code für viele Oerationen auf Datentypen komplett automatisch vom Compiler generieren zu lassen).

  • Pattern Matching erlaubt eine sehr klare Verarbeitung von ADTs

  • Eleganz: Viele Algorithmen lassen sich sehr kompakt und nah an der Problemdomäne formulieren.

  • Data Encapsulation durch Module

  • Weniger Bugs durch

    • Purity, keine Seiteneffekte

    • Starke typisierung. Keine NPEs !

    • Hohe Abstraktion, Programme lassen sich oft wie eine deklarative Spezifikation des Algorithmus lesen

    • sehr gute Testbarkeit durch "Composobility"

    • Memory Management (sehr schneller GC)

    • Modulare Programme. Es gibt ein sehr einfaches aber effektive Modul System und eine grosse Vielzahl kuratierter Bibliotheken.

    ("Ich habe in 5 Jahre Haskell noch nicht ein einziges Mal debuggen müssen")

  • Performance: keine VM, sondern sehr optimierter Maschinencode. Mit ein wenig Feinschliff lassen sich oft Geschwindigkeiten wie bei handoptimiertem C-Code erreichen.

toc for code chapters (still in german)

  • Werte

  • Funktionen

  • Listen

  • Lazyness

    • List comprehension
    • Eigene Kontrollstrukturen
  • Algebraische Datentypen

    • Summentypen : Ampelstatus
    • Produkttypen (int, int) Beispiel: Baum mit Knoten (int, Ampelstatus) dann mit map ein Ampelstatus
  • deriving (Show, Read) für einfache Serialisierung

  • Homoiconicity (Kind of)

  • Maybe Datentyp

    • totale Funktionen
    • Verkettung von Maybe operationen
      (um die "dreadful Staircase" zu vermeiden) => Monoidal Operations
  • explizite Seiten Effekte -> IO Monade

  • TypKlassen

    • Polymorphismus z.B. Num a, Eq a
    • Show, Read => Homoiconicity bei Serialisierung
    • Automatic deriving (Functor mit Baum Beispiel)
  • Testbarkeit