Skip to content

Instantly share code, notes, and snippets.

@chemist
Created June 21, 2013 06:07
Show Gist options
  • Save chemist/5829214 to your computer and use it in GitHub Desktop.
Save chemist/5829214 to your computer and use it in GitHub Desktop.
objects in haskell
{-# LANGUAGE RecordWildCards #-}
module Main where
import Data.Time
import Data.Set
import Data.Monoid
type Req = (String, String)
type Rules = [String]
type Ip = String
data IpObject = IpObject
{ ip :: Ip
, time :: UTCTime
, request :: Req -> IpObject
, banned :: Bool
, rules :: Rules
, updateRules :: Rules -> IpObject
, render :: IO ()
}
instance Show IpObject where
show IpObject{..} = show ip ++ " " ++ show time ++ " " ++ show banned ++ " " ++ show rules
instance Eq IpObject where
(==) x y = ip x == ip y
instance Ord IpObject where
compare x y = compare (ip x) (ip y)
type Base = Set IpObject
main = print "hello"
ipObj :: Ip -> UTCTime -> Bool -> Rules -> IpObject
ipObj i t s r = IpObject
{ ip = i
, time = t
, request = reqFun
, banned = s
, rules = r
, updateRules = \x -> ipObj i t s (r <> x)
, render = renderFun
}
reqFun = undefined
renderFun = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment