How to call Haskell functions from C

Michele Riva
Level Up Coding
Published in
3 min readMay 4, 2021

--

After almost 50 years, the C programming language is still considered one of the fasts low-level code options. It is a relatively small language, quite easy to learn, widely diffused, and universally known to be fast. Really, really fast.

The problem with C is that some algorithms may become difficult to write, read, and debug due to the language's low-level nature. Sometimes, writing those algorithms in another language may be a good choice.

There are a lot of languages that can interoperate with C. However, there’s one that is completely different from it and still is an awesome alternative for beautifully writing complex algorithms: Haskell.

In fact, Haskell is a purely functional programming language that has many advantages over C:

  • Higher-level programming language
  • No null
  • No side effects at all
  • More modular code
  • Lazy evaluation
  • Easier to parallelize

and so on.

In terms of performances, most of the time, Haskell's execution speed is really close to C. That makes Haskell a good alternative for writing complex algorithms more quickly.

--

--