-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add boolFieldM which allows using the Compiler monad #565
Conversation
This commits adds the helper boolFieldM. In contrast to boolField it allows using the Compiler monad in the passed function. boolField is also redefined in terms of boolFieldM. Closes jaspervdj#564
Any news on this PR? |
Just curious, what are you using this for? |
I'm building a multi-level navigation menu by iterating over
Definitely looks like something that might be useful from time to time. |
I'm fine merging this unless this conflicts with the progress on better error messages @bergus |
No, doesn't really conflict with that (the collision is easy to resolve), however I'm not sold on the name Also I'm currently experimenting with class ContextFieldable a where -- a horrible name. Suggestions?
toContextField :: a -> Compiler ContextField
instance ContextFieldable ContextField where
toContextField = return
instance ContextFieldable a => ContextFieldable (Compiler a) where
toContextField = (>>= toContextField)
instance ContextFieldable [Char] where
toContextField = return . StringField
instance ContextFieldable Bool where
toContextField True = return EmptyField
toContextField False = compilerNoResult "false"
instance ContextFieldable a => ContextFieldable (Maybe a) where
toContextField = maybe (compilerNoResult "false") toContextField
--------------------------------------------------------------------------------
functionContext :: ContextFieldable c => String -> ([String] -> Item a -> c) -> Context a
functionContext key value = Context $ \k args item ->
if k == key
then mapError (("In field "++key):) $ toContextField $ value args item
else compilerNoResult $ "Tried field " ++ key
context :: ContextFieldable c => String -> (Item a -> c) -> Context a
context key = functionContext key . const which would allow |
Oh yeah something like that would work as well. I would just call the typeclass |
Done in #1044 |
This commits adds the helper boolFieldM. In contrast to boolField it
allows using the Compiler monad in the passed function.
boolField is also redefined in terms of boolFieldM.
Closes #564