Hello World In Koka

Hello World in Koka Featured Image

At this point in the Hello World in Every Language series, we’re closing in on the 50th article. How cool is that? For right now though, we have something even cooler: Hello World in Koka by Bassem Mohamed.

Table of Contents

Koka Background

Koka is a function-oriented programming language created by Microsoft researcher Daan LeijenOpens in a new tab.. Leijan created Koka to separate pure values from side-effecting computations. According to WikipediaOpens in a new tab., a function or expression is said to have a side effect if it modifies some state outside of its local environment.

In addition, Koka has many features that help programmers easily change their data types and code organization correctly while having a small language core with a familiar JavaScript-like syntax.

Fun Fact: the word ‘Koka’ (or 効果) means “effect” or “effective” in Japanese

Hello World in Koka

Now, let’s see how we can print a simple “Hello World” in Koka:

function main() 
{
  println("Hello, World!")
}

Just like many other programming languages, the main function is the starting point of the code execution. To print, we use println, a built-in method that prints a given string or variable to the console.

Like many of the high-level language implementations in this series, this one wasn’t too bad. Wanna try it out? Check out this online Koka editorOpens in a new tab..

How to Run the Solution

If you want to run Koka at your local machine, you can always install the Koka compiler and try the snippet locally. There are no binary releases of Koka though. You will have to build the compiler yourself. Don’t worry! It sounds harder than it is. All you need to do is install the following programs:

Now, you need to clone the Koka repositoryOpens in a new tab. to your local environment. Then, run the following commands at the local repo directory:

npm install
cabal update
cabal install alex
jake

jake is the command for building the compiler, and it also runs the Koka interactive environment where you can play around with Koka.

To actually run the solution, you need to run the following commands:

:l YOUR_FILE.kk
main()

There you go! The sky is the limit now. But if you need help, you can check out the Koka bookOpens in a new tab. and the documentation.

Sample Programs in Every Language

That’s it for Hello world in Koka. Please share your thoughts with us in the comments. Also, why not check out the rest of the series?

As you can probably expect, we are always looking for contributors. If you have a chance, check out the sample programs repository.Opens in a new tab.

Bassem Mohamed

Bassem is a developer, tech enthusiast. Started his career as a web developer in a digital marketing agency. After one year of hard work, it got him enough experience to land a job as a core system engineer in one of the biggest banks in Egypt. Being a junior developer and 24 years old, he still has a long way to go. In his spare time, You can find him contributing to Github, Attending a Ted talk or maybe writing a tech article.

Recent Posts