You don't have javascript enabled. Good luck! :(

TH で生成されるコードの確認方法

最終更新日: 2018/08/04

確認方法

ファイルの先頭に {-# OPTIONS_GHC -ddump-splices #-} を付けるだけで良い。

実際に生成されるコード

さきほどの例を実行すると次のようなコードが生成されていることがわかる。

Tips8.hs:(12,1)-(14,2): Splicing declarations
    mkYesod
      "App"
      ([yesod-core-1.6.6:Yesod.Routes.TH.Types.ResourceLeaf
          (((((yesod-core-1.6.6:Yesod.Routes.TH.Types.Resource "Check1R")
                [yesod-core-1.6.6:Yesod.Routes.TH.Types.Static "check1"])
               ((yesod-core-1.6.6:Yesod.Routes.TH.Types.Methods Nothing) ["GET"]))
              [])
             True)])
  ======>
    instance ParseRoute App where
      parseRoute
        = (\ f_a7aC x_a7aD
             -> (f_a7aC ghc-prim-0.5.2.0:GHC.Tuple.()) x_a7aD ::
             (()
              -> ([text-1.2.3.0:Data.Text.Internal.Text],
                  [(text-1.2.3.0:Data.Text.Internal.Text,
                    text-1.2.3.0:Data.Text.Internal.Text)])
                 -> Maybe (Route a_a7aE))
             -> ([text-1.2.3.0:Data.Text.Internal.Text],
                 [(text-1.2.3.0:Data.Text.Internal.Text,
                   text-1.2.3.0:Data.Text.Internal.Text)])
                -> Maybe (Route a_a7aE))
            helper_a7aB
        where
            helper_a7aB env7459_a7aw req7459_a7ax
              = helper7459_a7ay (fst req7459_a7ax)
              where
                  helper7459_a7ay
                    ((ghc-prim-0.5.2.0:GHC.Types.:) "check1"
                                                    ghc-prim-0.5.2.0:GHC.Types.[])
                    = ((((\ _ _ x_a7aA _ -> x_a7aA) (error "mdsGetHandler"))
                          env7459_a7aw)
                         (Just Check1R))
                        req7459_a7ax
                  helper7459_a7ay _
                    = ((((\ _ _ x_a7az _ -> x_a7az) (error "mds404")) env7459_a7aw)
                         Nothing)
                        req7459_a7ax
    instance RenderRoute App where
      data Route App
        = Check1R
        deriving (Show, Eq, Read)
      renderRoute Check1R
        = (((text-1.2.3.0:Data.Text.pack "check1")
              ghc-prim-0.5.2.0:GHC.Types.: []),
           [])
    instance RouteAttrs App where
      routeAttrs Check1R {}
        = containers-0.5.11.0:Data.Set.Internal.fromList []
    resourcesApp ::
      [yesod-core-1.6.6:Yesod.Routes.TH.Types.ResourceTree String]
    resourcesApp
      = [yesod-core-1.6.6:Yesod.Routes.TH.Types.ResourceLeaf
           (((((yesod-core-1.6.6:Yesod.Routes.TH.Types.Resource "Check1R")
                 [yesod-core-1.6.6:Yesod.Routes.TH.Types.Static "check1"])
                ((yesod-core-1.6.6:Yesod.Routes.TH.Types.Methods Nothing) ["GET"]))
               [])
              True)]
    type Handler = HandlerFor App
    type Widget = WidgetFor App ghc-prim-0.5.2.0:GHC.Tuple.()
    instance YesodDispatch App where
      yesodDispatch env1847_a7at req1847_a7au
        = helper1847_a7av
            (wai-3.2.1.2:Network.Wai.Internal.pathInfo req1847_a7au)
        where
            helper1847_a7av
              ((ghc-prim-0.5.2.0:GHC.Types.:) "check1"
                                              ghc-prim-0.5.2.0:GHC.Types.[])
              = case
                    wai-3.2.1.2:Network.Wai.Internal.requestMethod req1847_a7au
                of
                  "GET"
                    -> (((yesodRunner getCheck1R) env1847_a7at) (Just Check1R))
                         req1847_a7au
                  _ -> (((yesodRunner (Data.Functor.void badMethod)) env1847_a7at)
                          (Just Check1R))
                         req1847_a7au
            helper1847_a7av _
              = (((yesodRunner (Data.Functor.void notFound)) env1847_a7at)
                   Nothing)
                  req1847_a7au