Book Image

Haskell Data Analysis cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis cookbook

By: Nishant Shukla

Overview of this book

Step-by-step recipes filled with practical code samples and engaging examples demonstrate Haskell in practice, and then the concepts behind the code. This book shows functional developers and analysts how to leverage their existing knowledge of Haskell specifically for high-quality data analysis. A good understanding of data sets and functional programming is assumed.
Table of Contents (14 chapters)
13
Index

Responding to IRC messages

Another way to interact with IRC in Haskell is by using the Network.SimpleIRC package. This package encapsulates much of the low-level networking and also provides useful IRC interfaces.

In this recipe, we will respond to messages in a channel. If any user types in the trigger phrase, in our case "host?", then we will reply to that user with their host address.

Getting ready

Install the Network.SimpleIRC package:

$ cabal install simpleirc

To test out the IRC bot, it is helpful to install an IRC client. A decent IRC client is Hexchat, which can be downloaded from http://hexchat.github.io. For a terminal-based IRC client, Irssi is one of the best: http://www.irssi.org.

How to do it…

Create a new file, which we call Main.hs, and do the following:

  1. Import the relevant libraries:
    {-# LANGUAGE OverloadedStrings #-}
    
    import Network.SimpleIRC
    import Data.Maybe
    import qualified Data.ByteString.Char8 as B
  2. Create an event handler when a message is received. If the...