2016-01-23 83 views
1

我一直在下面this tutorial学习耶索德,并正尝试运行这个简单的形式:当我runhaskell forms.hs,我得到这个错误可保存格式类型耶索德

{-# LANGUAGE TypeFamilies    #-} 
{-# LANGUAGE QuasiQuotes    #-} 
{-# LANGUAGE MultiParamTypeClasses  #-} 
{-# LANGUAGE TemplateHaskell   #-} 
{-# LANGUAGE OverloadedStrings   #-} 
{-# LANGUAGE ViewPatterns    #-} 
import Control.Applicative((<$>),(<*>)) 
import Yesod 

data App = App 

mkYesod "App" [parseRoutes| 
/accum Accum GET 
|] 

instance Yesod App 

instance RenderMessage App FormMessage where 
    renderMessage _ _ = defaultFormMessage 

data Info = Info 
    { deposit :: Double 
    , rate :: Double 
    , years :: Double 
    } 

aform :: AForm App App Info 
aform = Info 
    <$> areq doubleField "Deposit" Nothing 
    <*> areq doubleField "Rate" Nothing 
    <*> areq doubleField "Years" Nothing 

accum x = deposit x * (1 + rate x * years x) 

mform = renderTable aform 

getAccum :: Handler RepHtml 
getAccum = do 
    ((result, widget), enc) <- runFormGet mform 
    case result of 
     FormSuccess info -> defaultLayout [whamlet|<p> #{show (accum info)} |] 
     _    -> defaultLayout [whamlet| 
     <form method=get [email protected]{Accum} enctype=#{enc}> 
     <table> 
      ^{widget} 
     <input type=submit> 
     |] 

main = warpDebug 2012 App 

forms.hs:27:10: 
    ‘AForm’ is applied to too many type arguments 
    In the type signature for ‘aform’: aform :: AForm App App Info 

后用类型签名的一些变化来破坏我,我不断收到错误。该ghci的:info AForm读取

Prelude Yesod> :info AForm 
type role AForm nominal nominal 
newtype AForm (m :: * -> *) a 

但更改aform :: AForm (App -> App) Info给了我这个错误:

forms.hs:27:17: 
    The first argument of ‘AForm’ should have kind ‘* -> *’, 
     but ‘App -> App’ has kind ‘*’ 

上的任何想法如何解决这个问题?

回答

1

类型签名areq是:

areq :: (RenderMessage site FormMessage, HandlerSite m ~ site, MonadHandler m) => Field m a -> FieldSettings site -> Maybe a -> AForm m a 

说明它是如何将两个参数,并且第一个参数是MonadHandler一个实例。因此,您在aform上的签名将需要具有相同的参数。在你的代码,这可能是这样的:

aform :: AForm (HandlerT App IO) Info 

或缩写形式:

aform :: AForm Handler Info 

看一看the car example in the Yesod book