Skip to content

Instantly share code, notes, and snippets.

@3noch
Created May 9, 2014 20:19
Show Gist options
  • Save 3noch/ffc2f3c8fbbb96b6ab47 to your computer and use it in GitHub Desktop.
Save 3noch/ffc2f3c8fbbb96b6ab47 to your computer and use it in GitHub Desktop.
module Rules where
Schema ( "time" =: timestamp
, "enabled" =: bool )
data Value = VInt Int
| VString String
| VBool Bool
| VList [Value]
| VSchema [(String, Value)]
| VFail Value Rule
type Rule = Check (Value -> Value) String
| AnyOf [Rule]
| ForAll Rule
isFail :: Value -> Bool
isFail (VFail _ _) = True
isFail _ = False
bool :: Rule
bool = Check isBool "must be boolean" where
isBool (VBool x) = VBool x
isBool x = VFail x bool
str :: Rule
str = Check isStr "must be a string" where
isStr (VString x) = VString x
isStr x = VFail x str
numeric :: Rule
numeric = Check isNum "must be a number" where
isNum (VInt x) = VInt
isNum x = VFail x numeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment