Chris Stryczynski

Software Developer / Consultant

My introduction with digestive-functors

Posted on: 19/04/2017

Update 2019: After having struggled with digestive-functors, I wouldn’t recommend it… Instead I uhhh wrote my own form validation library over period of several months https://github.com/chrissound/NiobiumCoconut. So I’d recommend that as an alternative to digestive-functors!

Firstly, you can construct ‘invalid’ forms that result in runtime errors (pain to debug too). And trying to do slightly ‘simple’ form stuff can be difficult https://github.com/jaspervdj/digestive-functors/issues/144


Form is a type that encapsulates ‘inputtable’ form inputs and validation rules. View is a type that encapsulates a sort of ‘form state’ - a form, some input, their errors.

runView is a conventional function that is used to create a View from a Form and input. So there are a few ‘bindings’ for common web frameworks (snap / scotty / happstack) that implement this function.

If you were to implement your own runView function without any web framework, you’d essentially need to create a mock request (Network.Wai related).

data User = User
    { userName :: Text
    , userMail :: Text
    } deriving (Show)
    
userForm :: Monad m => Form Text m User
userForm = User
  <$> "name" .: text Nothing
  <*> "mail" .: check "Not a valid email address" checkEmail (text Nothing)

Gotchas: Get requests don’t get processed with the relevant runForm functions implemented by all the web framework bindings. No idea. http://stackoverflow.com/questions/43480171/why-do-form-submissions-via-get-requests-not-get-processed

Comments

No comments, yet!

Submit a comment