2.6 KiB

What is Haskell?

Haskell is a purely functional programming language.

What does that mean? What isn't a functional programming language? Well, just about every programming language I've used before: C, Python, Rust, MATLAB are all imperative[^2]1. To do things, you give the computer a list of tasks to execute. Here's an example:

If I want to compute a factorial, I'd probably say take this value, and multiply it a whole bunch of times until you get to an end condition. The computer may change state at this point, where your input variable gets overwritten with the result, or some thing inside the task list, such as an iterator, changes to a value that can create a different result if run again.

  • What is a 'state' for a computer really? #Follow-Up #Haskell 2025-02-28 📅 2025-03-11 2025-07-28

A state for a computer is really just a snapshot of time of all the memory in the computer.

Functional programming languages do not do this. Instead of using iteratives like that or having the possiblity of functions changing variable states, everything is instead immutable. If I define a function for a factorial, I define what a factorial is, rather than explicit steps to compute one. Then, when I apply the 'function' to an input, the output is something new: the function applied to that variable that is fundamentally not an execution of the function or a wrought product of the original input. This is maybe what a monad is.

  • [-] What is a 'monad' really? #Follow-Up #Haskell 2025-02-28 📅 2025-03-11 2025-07-28

There's a special property about functions that can be called multiple times with the same parameters being guaranteed to return the same result: Referential Transparency. This property allows us to deduce and then even proved that a function does exactly what it is supposed to, every time.

Haskell is a statically typed language, and supports type inference. It has been developed since 1987, with the first stable version of the language coming out ofthe Haskell Report in 2003.

What I need to dive in:

A Haskell compiler! The recommended one is GHC.

GHC can compile code but it can also run from the prompt interactively, by running 'ghci'. You can list functions from the current folder using ':l filename'. The file can be reloaded using ':r'

I got Haskell installed and set up the Haskell Language Server for Neovim. That took a little bit more effort than anticipated but eventually I got it to work. My Lua files are so fucked. ChatGPT helped a lot though.


  1. not really Rust, because I believe Rust has functional programming support. ↩︎