Menu

Christian Stryczynski

Freelance software developer. Haskelling at night. Hopefully unconventional. Fan of Dvorak

My introduction with digestive-functors

`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 implemention 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 relevent `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

Written by Christian Stryczynski on Monday April 3, 2017

Permalink - Tag: haskell

« Disable Haskell warnings and errors in a single file - Awesome podcasts / talks about software development »