我正在使用斯科蒂和
Text.Blaze.Html5
Text.Digestive
-
我想要实现的是一个选项列表,如下所示。
我有一个Option
sum 类型,并希望将用户限制在这些选项中。
data Options = Option1 | Option2 | Option3 | Option4 deriving Show
我的问题是 Text.Digestive.choice
我不知道如何使用它,并感谢您在正确方法上的帮助以实现此目的。
我试图使用下面的代码,但努力让它正确。
{-# LANGUAGE OverloadedStrings #-}
import ClassyPrelude
import Web.Scotty.Trans
import Domain.Auth.Types
import Text.Digestive.Scotty
import qualified Text.Digestive.Form as DF
import qualified Text.Digestive.View as DF
import Text.Digestive.Form ((.:))
import Adapter.HTTP.Common
import Adapter.HTTP.Web.Common
import Katip
import Text.Blaze.Html5 ((!))
import qualified Text.Digestive.Blaze.Html5 as DH
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
import qualified Data.Text as T
registerForm :: Monad m => Form Text m Register
registerForm = Register
<$> "name" .: text Nothing
<*> "options" .: choice options Nothing
where
options= [(Option1, "Option1"),(Option2, "Option2"), (Option3,
"Option3"),(Option4, "Option4")]
registerView:: View H.Html -> H.Html
registerView view = do
label "name" view "Name: "
inputText "name" view
H.br
label "options" view "Options: "
inputSelect "options" view
H.br
编译代码时出现以下错误。
[14 of 23] Compiling Adapter.HTTP.Web.Auth ( src/Adapter/HTTP/Web/Auth.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Adapter/HTTP/Web/Auth.o )
/root/work/src/Adapter/HTTP/Web/Auth.hs:107:29: error:
• Couldn't match type ‘Text’ with ‘Char’
arising from the literal ‘"Option1"’
• In the first argument of ‘pack’, namely ‘"Option1"’
In the expression: pack "Option1"
In the expression: (Option1, pack "Option1")
|
107 | options= [(Option1,pack "Option1"),(Option2,pack "Option2"),(Option3,pack "Option3"),(Option4,pack "Option4")]
| ^^^^^
/root/work/src/Adapter/HTTP/Web/Auth.hs:129:7: error:
• Couldn't match expected type ‘(Text -> DF.View H.Html -> H.Html)
-> [Char]
-> DF.View [Text]
-> [Char]
-> DF.View [Text]
-> (H.Html -> H.Html)
-> H.Html
-> H.Html’
with actual type ‘blaze-markup-0.8.0.0:Text.Blaze.Internal.MarkupM
()’
• The function ‘H.label’ is applied to 7 arguments,
but its type ‘H.Html
-> blaze-markup-0.8.0.0:Text.Blaze.Internal.MarkupM ()’
has only one
In the expression:
H.label
"Options" DH.inputSelect "package.category" view "group" view H.div
In the second argument of ‘($)’, namely
‘H.label
"Options" DH.inputSelect "package.category" view "group" view H.div
$ errorList' "option"’
|
129 | H.label "Options"
No tix files found in /root/work/.stack-work/install/x86_64-linux/lts-10.3/8.2.2/hpc/, so not generating a unified coverage report.
-- While building custom Setup.hs for package hauth-0.1.0.0 using:
/root/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.0.1.0 build lib:hauth exe:hauth-exe test:hauth-test --ghc-options "-hpcdir .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/hpc -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
您的帮助将不胜感激