[ create a new paste ] login | about

Link: http://codepad.org/R2lYXkIY    [ raw code | output | fork | 1 comment ]

johannes - Haskell, pasted on Oct 11:
module Main where

import Network.Libev
import Foreign.C.Types

-- This is the watcher callback
stdinCallback :: EvLoopPtr -> EvIoPtr -> CInt -> IO ()
stdinCallback loop watcher events = do
   r <- getLine
   case r of
      "exit" -> evIoStop loop watcher
      _      -> print $ "You said: " ++ r
   
main :: IO ()
main = do
   -- Use the default event loop
   loop <- evDefaultLoop 0
   
   -- Create a watcher
   watcher <- mkEvIo
   
   -- mkIoCallback translates our Haskell callback to a function 
   -- callable from foreign code
   cback <- mkIoCallback stdinCallback
   
   -- Initialize an IO watcher that responds to EV_READ events on STDIN
   let stdin = 0 in evIoInit watcher cback stdin ev_read
   
   -- Start the watcher
   evIoStart loop watcher
   
   -- Now wait for events to arrive
   evLoop loop 0
   
   print "Exiting..."


Output:
1
2
Error occurred
ERROR "t.hs" - Can't find imported module "Network.Libev"


Create a new paste based on this one


Comments:
posted by johannes on Oct 11
A simple "hello world" application using HLibev -- the Haskell FFI wrapper for Libev.
reply