2016-01-23 113 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