Created
May 9, 2014 20:19
-
-
Save 3noch/ffc2f3c8fbbb96b6ab47 to your computer and use it in GitHub Desktop.
This file contains 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
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