警告:匹配字符串时,模式匹配重叠

时间:2011-09-24 12:04:14

标签: haskell

我正在尝试在Haskell中创建一个简单的url路由,并且无法绕过警告:

Warning: Pattern match(es) are overlapped
             In a case alternative: "/" -> ...
Ok, modules loaded: Main.

摘录:

{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.Debug (debug)
import Network.HTTP.Types (statusOK, status404)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import Data.ByteString.Char8 (unpack)
import Data.ByteString.Lazy.Char8 (pack)
import qualified Data.Text.Lazy as T
import Control.Monad.IO.Class (liftIO, MonadIO)

application req = do
  case unpack $ rawPathInfo req of
    "/items" -> itemsJSON 
    "/" -> indexPage
    _ ->  return $ responseLBS status404 [("Content-Type", "text/plain")]
          "Not found"

indexPage = do
  page <- liftIO $ L.readFile "templates/index.html"
  return $ responseLBS statusOK [("Content-Type", "text/html; charset=utf-8")] page

itemsJSON  =
  return $ responseLBS statusOK 
    [("Content-Type", "application/json; charset=utf-8")] "hi"

main =  do
  run 3000 $ debug $ application

UPD: 用完整的程序替换了片段,

$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 6.12.1

1 个答案:

答案 0 :(得分:10)

这是bug,并在较新版本的GHC中修复。