In this post we will compare these three languages with simple examples and see how much more syntax we need to write in Haskell to do imperative style programming.
A simple for loop with print to
The similarities are quiet obvious and none of these snippets is more or less complex than the others. One should note that the
forM_ is a function.
One common task in programming is to create endless loops that does something and then sleeps for a while and repeat. The following example implements a
while true loop and logs the current date to a temporary file.
Please note that in order to use the
async function. I omitted this kind of extra “noise” to make the syntax comparisons of the
while loop more clear. I also removed the import statements for Python and Haskell. Haskells
main function is also ommited. As we can see there is not much difference between the code examples. The Haskell versions of doing I/O (reading time, writing to file and sleep) is syntactically the shortest one. Of course high expressivenesses, and thus fewer lines of code, does not imply simplicity. A language that is very terse tend to be more complex to understand. That is because it requires the programmer to know the meaning of different short names, standard functions and operators.