English 中文(简体)
如果有的话,在美德州诺克
原标题:Where is parseRoutesNoCheck in Yesod

I started to learn Haskell language and Yesod web framework. When I tried to use "parseRoutesNoCheck" for mkYesod, however, the compiler could not match the return type (Resource) of parseRoutesNoCheck.

$ ghc simple_yesod.hs
[1 of 1] Compiling Main             ( simple_yesod.hs, simple_yesod.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Loading package bytestring-0.9.1.10 ... linking ... done.
Loading package array-0.3.0.2 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
Loading package deepseq-1.1.0.2 ... linking ... done.
Loading package text-0.11.0.6 ... linking ... done.
Loading package path-pieces-0.0.0 ... linking ... done.
Loading package pretty-1.0.1.2 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package web-routes-quasi-0.7.1 ... linking ... done.

simple_yesod.hs:9:36:
    Couldn t match expected type `yesod-core-0.9.2:Yesod.Internal.RouteParsing.Resource 
                with actual type `Resource 
    In the return type of a call of `Resource 
    In the expression:
      Resource "PageR" [StaticPiece "page", SinglePiece "String"] ["GET"]
    In the second argument of `mkYesod , namely
      `[Resource
          "PageR" [StaticPiece "page", SinglePiece "String"] ["GET"],
        Resource
          "UserR" [StaticPiece "user", SinglePiece "String"] ["GET"]] 

看来,Im使用错误的 par子,但正确的模块在哪里?

简单易懂。

{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, OverloadedStrings #-}
import Yesod
import Web.Routes.Quasi.Parse
import qualified Text.Blaze.Html5 as H

data Test = Test {
  }

mkYesod "Test" [parseRoutesNoCheck|
/page/#String      PageR   GET
/user/#String      UserR   GET
|]

instance Yesod Test where
  approot _ = "" 
  defaultLayout widget = do
                      content <- widgetToPageContent widget
                      hamletToRepHtml [hamlet|
<!DOCTYPE html>

<html>
  <head>
    <title>#{pageTitle content}
  <body>
    <ul id="navbar">
    <div id="content">
      ^{pageBody content}
|]


getUserR :: String -> Handler RepHtml
getUserR userName = defaultLayout
                    (do
                      setTitle $ H.toHtml $ "Hello " ++ userName
                      addHamlet $ html userName
                    )
    where
      html page = [hamlet|
 <h1>User: #{userName}
 <p>This page is for user: #{userName}
 |]

getPageR :: String -> Handler RepHtml
getPageR pageName = defaultLayout
                    (do
                      setTitle $ H.toHtml $ "Article: " ++ pageName
                      addHamlet $ html pageName
                    )
    where
      html page = [hamlet|
 <h1>Page: #{pageName}
 <p>This page is for page: #{pageName}
 |]

main :: IO ()
main = do
  warpDebug 3000 $ Test

I m 采用Glas Haskell Compiler, 第7.0.3版,是正分-0.9.2。

问题回答

页: 1 而不是parseRoutes NoCheck。 您也不妨在和删除<条码>进口网>。 自<代码>Yesod模块输出parseRoutes以来。

这里是经过我提到的修改的完整的法典。

{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, OverloadedStrings #-}
module Main where
import Yesod
import qualified Text.Blaze.Html5 as H


data Test = Test {
  }

mkYesod "Test" [parseRoutes|
/page/#String      PageR   GET
/user/#String      UserR   GET
|]

instance Yesod Test where
  approot _ = "" 
  defaultLayout widget = do
                      content <- widgetToPageContent widget
                      hamletToRepHtml [hamlet|
<!DOCTYPE html>

<html>
  <head>
    <title>#{pageTitle content}
  <body>
    <ul id="navbar">
    <div id="content">
      ^{pageBody content}
|]


getUserR :: String -> Handler RepHtml
getUserR userName = defaultLayout
                    (do
                      setTitle $ H.toHtml $ "Hello " ++ userName
                      addHamlet $ html userName
                    )
    where
      html page = [hamlet|
 <h1>User: #{userName}
 <p>This page is for user: #{userName}
 |]

getPageR :: String -> Handler RepHtml
getPageR pageName = defaultLayout
                    (do
                      setTitle $ H.toHtml $ "Article: " ++ pageName
                      addHamlet $ html pageName
                    )
    where
      html page = [hamlet|
 <h1>Page: #{pageName}

一种良好的想法是,在你学习阶段重述现有例子(以及这个问题的所有其他内容)。 法典的刀切通常见于《好书》或《大刀》中,人们可以从这些来源学习。


Edit:我没有完整的答案。 注

我希望,这更说明问题。





相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签