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 Leijen. Leijan created Koka to separate pure values from side-effecting computations. According to Wikipedia, 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 editor.
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:
- The Haskell platform (version 7.4 or later).
- The NodeJS runtime (version 4.2 LTS or later).
- Git for version control.
Now, you need to clone the Koka repository 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 book 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.
Recent Posts
While creating some of the other early articles in this series, I had a realization: something even more fundamental than loops and if statements is the condition. As a result, I figured we could...
Today, we're expanding our concept map with the concept of loops in Python! Unless you're a complete beginner, you probably know a thing or two about loops, but maybe I can teach you something new.