Haskell is one of powerful functional programming language. More specific, it is a polymorphically statically typed, lazy, purely functional language. It is the good language for expressing math equation and logic naturally. Haskell is based on the lambda calculus, thus it use lambda as the logo.

Despite of functional paradigm nature, Haskell is very good for network and distributed system application. It can also applied as application on cloud computing.

After installing haskell on Raspberry Pi, it is worth to test what Haskell can do. This article will discuss about creating a simple Echo Server on Raspberry Pi using Haskell programming language.

In this article I use:

  1. Raspberry Pi model B 512MB RAM
  2. Raspbian Wheezy 2013-07-26 hardfloat

Overview

What we really want to build in this article is a modified Echo server. This program will run forever (infinite loop) and listen on port specified by user when invoking program. Like any socket-based application, when a connection come, it will accept and process it according to our app’s logic. Our logic is so simple. Whenever user connect to server using telnet, this server will echo every line they write (echo). However when they write “ping” without quote, the server will reply with “pong”.

Preparation

Make sure you have install Haskell on your Pi.

Writing code to Pi can be done using any method. You can access your Pi remotely or access directly. At least, make sure you can create a file and write it.

Writing the Code

Write this snippet and save it as “echoserver.hs”:

Also, make sure you pay attention to the indentation.

This code is simple and should run on any architecture supported by GHC, including our Pi.

Build and Testing

To build the above code, run this command (assume the code is saved as echoserver.hs):

The -O2 flags are used to apply every non-dangerous optimization, but might make the compilation time longer.

After compilation successful, you will have a new file name echoserver. To run the server do this on your Pi:

This will run a server and make it listen to port 5000.

Now on your local computer, open up command prompt / terminal and invoking telnet to connect to your Pi. Suppose our Pi is on address 192.168.1.11, do following:

which will connect us to Pi on port 5000.

You can test by write any line there. Good luck 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">