前提・実現したいこと
YesodでShakespearean Templatesを使用したGET POSTを実行したい。
公式サイト(A Yesod tutorial)のサンプルを入力しビルドしたのですが、下記のようなエラーがでます。
発生している問題・エラーメッセージ
サンプルコードを入力し、ビルドすると下記のようなエラーがでます。
[apo@localhost my-project]$ stack build Warning: /home/apo/doc/dev/making/Haskell/hs_yesod_mirror/my-project/my-project.cabal was modified manually. Ignoring /home/apo/doc/dev/making/Haskell/hs_yesod_mirror/my-project/package.yaml in favor of the cabal file. If you want to use the package.yaml file instead of the cabal file, then please delete the cabal file. my-project-0.0.0: unregistering (components added: exe:my-project) my-project-0.0.0: configure (lib + exe) Configuring my-project-0.0.0... my-project-0.0.0: build (lib + exe) Preprocessing library for my-project-0.0.0.. Building library for my-project-0.0.0.. [ 1 of 13] Compiling Model ( src/Model.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Model.o ) [ 2 of 13] Compiling Settings ( src/Settings.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Settings.o ) [ 3 of 13] Compiling Settings.StaticFiles ( src/Settings/StaticFiles.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Settings/StaticFiles.o ) [ 4 of 13] Compiling Import.NoFoundation ( src/Import/NoFoundation.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Import/NoFoundation.o ) [ 5 of 13] Compiling Paths_my_project ( .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/autogen/Paths_my_project.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Paths_my_project.o ) [ 6 of 13] Compiling Foundation ( src/Foundation.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Foundation.o ) [ 7 of 13] Compiling Import ( src/Import.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Import.o ) [ 8 of 13] Compiling Handler.Profile ( src/Handler/Profile.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Handler/Profile.o ) [ 9 of 13] Compiling Handler.Mirror ( src/Handler/Mirror.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Handler/Mirror.o ) /home/apo/doc/dev/making/Haskell/hs_yesod_mirror/my-project/src/Handler/Mirror.hs:7:30: error: ~ Couldn't match expected type ‘WidgetFor App ()’ with actual type ‘Language.Haskell.TH.Syntax.Q Language.Haskell.TH.Syntax.Exp’ ~ In the second argument of ‘($)’, namely ‘(widgetFile "mirror")’ In the expression: defaultLayout $ (widgetFile "mirror") In an equation for ‘getMirrorR’: getMirrorR = defaultLayout $ (widgetFile "mirror") | 7 | getMirrorR = defaultLayout $(widgetFile "mirror") | ^^^^^^^^^^^^^^^^^^^ /home/apo/doc/dev/making/Haskell/hs_yesod_mirror/my-project/src/Handler/Mirror.hs:11:53: error: ~ Couldn't match expected type ‘Text’ with actual type ‘[Char]’ ~ In the second argument of ‘ireq’, namely ‘"content"’ In the second argument of ‘($)’, namely ‘ireq textField "content"’ In a stmt of a 'do' block: postedText <- runInputPost $ ireq textField "content" | 11 | postedText <- runInputPost $ ireq textField "content" | ^^^^^^^^^ /home/apo/doc/dev/making/Haskell/hs_yesod_mirror/my-project/src/Handler/Mirror.hs:12:25: error: ~ Couldn't match expected type ‘WidgetFor App ()’ with actual type ‘Language.Haskell.TH.Syntax.Q Language.Haskell.TH.Syntax.Exp’ ~ In the second argument of ‘($)’, namely ‘(widgetFile "posted")’ In a stmt of a 'do' block: defaultLayout $ (widgetFile "posted") In the expression: do postedText <- runInputPost $ ireq textField "content" defaultLayout $ (widgetFile "posted") | 12 | defaultLayout $(widgetFile "posted") | ^^^^^^^^^^^^^^^^^^^ -- While building custom Setup.hs for package my-project-0.0.0 using: /home/apo/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 build lib:my-project exe:my-project --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always" Process exited with code: ExitFailure 1
該当のソースコード
src/Handler/Mirror.hs
module Handler.Mirror where import Import import qualified Data.Text as T getMirrorR :: Handler Html getMirrorR = defaultLayout $(widgetFile "mirror") postMirrorR :: Handler Html postMirrorR = do postedText <- runInputPost $ ireq textField "content" defaultLayout $(widgetFile "posted")
templates/mirror.hamlet
<h1> Enter your text <form method=post action=@{MirrorR}> <input type=text name=content> <input type=submit>
templates/posted.hamlet
<h1>You've just posted <p>#{postedText}#{T.reverse postedText} <hr> <p><a href=@{MirrorR}>Get back
試したこと
hamlet内の引数を削除してみましたが、エラーが改善されませんでした。
引数の問題ではないようです。
補足情報(FW/ツールのバージョンなど)
stack version : 1.7.1
lts : lts-12.10
ファイル作成までの流れ
stack new my-project yesod-sqlite && cd my-project stack install yesod-bin --install-ghc yesod add-handler Name of route (without trailing R): Mirror Enter route pattern (ex: /entry/#EntryId): /mirror Enter space-separated list of methods (ex: GET POST): GET POST
src/Foundation.hsファイルに下記を追加
isAuthorized MirrorR _ = return Authorized
全ソースコード
https://github.com/ringo-apo/hs_yesod_mirror
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/27 22:43
2018/09/28 01:56
2018/09/28 03:01