Skip to content
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

Blank page with applicativeDo #2

Open
cdupont opened this issue Jan 23, 2017 · 3 comments
Open

Blank page with applicativeDo #2

cdupont opened this issue Jan 23, 2017 · 3 comments

Comments

@cdupont
Copy link

cdupont commented Jan 23, 2017

reform-blaze doesn't seem to play well with applicativeDo (from GHC 8).
Just adding {-# LANGUAGE ApplicativeDo #-} to a code containing reform forms makes the happstack server to return a blank page.

@cdupont
Copy link
Author

cdupont commented Mar 15, 2017

@stepcut Any idea?

@stepcut
Copy link
Member

stepcut commented Mar 30, 2017

I can not duplicate this error. This is my current test code:

{-# language OverloadedStrings #-}
{-# language TypeFamilies #-}
{-# language ApplicativeDo #-}
module Main where

import Data.Text (Text)
import Text.Blaze.Html
import qualified Text.Blaze.Html5 as H
import Happstack.Server
import Text.Reform
import Text.Reform.Happstack
import Text.Reform.Blaze.Text


instance FormError AppError where
    type ErrorInputType AppError = [Input]
    commonFormError = AppCFE

data AppError = AppCFE  (CommonFormError [Input])

type SimpleForm = Form (ServerPartT IO) [Input] AppError Html ()

postForm :: SimpleForm Text
postForm =
  label ("Any text value: " :: Text) ++> inputText "" <* inputSubmit "submit"

route =
  do decodeBody (defaultBodyPolicy "/tmp/" 0 1000 1000)
     html <- reform (form ("/" :: Text)) "post" success Nothing postForm
     ok $ toResponse $ appTemplate "form" $ html
     where
       success :: Text -> ServerPartT IO Response
       success msg =
         ok $ toResponse $ appTemplate "Success" (H.p (toHtml msg))

appTemplate ttl bdy =
  do H.html $
      do H.head $ H.title ttl
         H.body bdy

main = simpleHTTP nullConf route

@stepcut
Copy link
Member

stepcut commented Mar 30, 2017

One thing you could try is using the bifunctors branch of reform:

https://github.com/Happstack/reform/tree/bifunctors

This switches from the local IndexedApplicative to Bifunctors and removes the bogus Monad Result instance. Despite those big sounding changes, all my code compiled with out changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants