我已经能够在 snap 应用程序中成功地使用具有简单形式的消化函子;但是,我在尝试处理隐藏输入列表时遇到了困难。有些东西我不太了解如何使用listOf
. 谁能指出我正确的方向?谢谢。
上一页呈现的 html 包括以下隐藏字段:
<div id='messageForm.recipients' class='inputList'>
<input type='hidden' name='messageForm.recipients.indices' value='0' />
<input type='hidden' id='messageForm.recipients.-1.email' name='messageForm.recipients.-1.email' value />
<input type='hidden' id='messageForm.recipients.0.email' name='messageForm.recipients.0.email' value='emai1l@email.com' />
<input type='hidden' id='messageForm.recipients.1.email' name='messageForm.recipients.1.email' value='email2@email.com' />
</div>
数据类型有:
data ConfirmMessage = ConfirmMessage {
isoDate :: T.Text,
subject :: T.Text,
body :: T.Text,
action :: T.Text,
recipients :: [Recipient]
} deriving (Show)
data Recipient = Recipient {
email :: T.Text
} deriving (Show)
表格是:
messageForm :: (Monad m) => Form T.Text m ConfirmMessage
messageForm = ConfirmMessage
<$> "isoDate" .: stringRead "Missing ISOdate" Nothing
<*> "subject" .: stringRead "Subject required" Nothing
<*> "body" .: stringRead "Body required" Nothing
<*> "action" .: stringRead "Missing action" Nothing
<*> "recipients" .: listOf recipientForm' Nothing
recipientForm' :: (Monad m) => Formlet T.Text m Recipient
recipientForm'= Recipient
<$> "email" .: text Nothing
我收到的错误消息是:
Couldn't match type `Text.Digestive.Form.Internal.FormTree
m0 v0 m0 Recipient'
with `Maybe Recipient -> Form T.Text m Recipient'
Expected type: Formlet T.Text m Recipient
Actual type: Text.Digestive.Form.Internal.FormTree
m0 v0 m0 Recipient
Relevant bindings include
recipientForm' :: Formlet T.Text m Recipient
(bound at src/Handler/TradeNotifyConfirm.hs:191:1)
In the expression: Recipient <$> "email" .: text Nothing
In an equation for `recipientForm'':
recipientForm' = Recipient <$> "email" .: text Nothing