Skip to content

Commit

Permalink
Add Haskell greeter.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinChen committed Feb 17, 2015
1 parent 3ef457d commit 99e3023
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/haskell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ $ websocketd --port=8080 --devconsole --passenv PATH ./count.hs
```

The passing of `PATH` was required for me because a typical Haskell installation of `runhaskell` does not go into `/usr/bin` but more like `/usr/local/bin`.

### Greeter

The greeter server waits for a line of text to be sent, then sends back a greeting in response, and continues to wait for more lines to come.

```
$ websocketd --port=8080 --devconsole --passenv PATH ./greeter.hs
```
13 changes: 13 additions & 0 deletions examples/haskell/greeter.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env runhaskell

import Control.Monad (unless)
import System.IO (stdin, hIsEOF)

-- | For each line FOO received on STDIN, respond with "Hello FOO!".
main :: IO ()
main = do
eof <- hIsEOF stdin
unless eof $ do
line <- getLine
putStrLn $ "Hello " ++ line ++ "!"
main

0 comments on commit 99e3023

Please sign in to comment.