Created
June 21, 2013 06:07
-
-
Save chemist/5829214 to your computer and use it in GitHub Desktop.
objects in haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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