2016-09-07 11 views
1

このエラーメッセージの理解に問題があります。'param'の使用に起因するあいまいな型変数 'a0'は、 '(Parsable a0)'という制約が解決されないようにします。

私は、次の輸入を持っている:

{-# LANGUAGE OverloadedStrings #-} 
module Main where 

import Web.Scotty 

import Control.Applicative 
import Control.Monad.IO.Class 
import Database.SQLite.Simple 
import Database.SQLite.Simple.FromRow 
import qualified Data.Text.Lazy as L 

エラーを引き起こしコード:

routes :: ScottyM() 
routes = do 
    post "/create" $ do 
    f <- param ("fa" :: L.Text) 
    file "create.html" 

とエラー:

• Ambiguous type variable ‘a0’ arising from a use of ‘param’ 
    prevents the constraint ‘(Parsable a0)’ from being solved. 
    Probable fix: use a type annotation to specify what ‘a0’ should be. 
    These potential instances exist: 
    instance Parsable Integer 
     -- Defined in ‘scotty-0.11.0:Web.Scotty.Action’ 
    instance Parsable L.Text 
     -- Defined in ‘scotty-0.11.0:Web.Scotty.Action’ 
    instance Parsable() 
     -- Defined in ‘scotty-0.11.0:Web.Scotty.Action’ 
    ...plus 7 others 
    ...plus 12 instances involving out-of-scope types 
    (use -fprint-potential-instances to see them all) 
• In a stmt of a 'do' block: f <- param ("f" :: L.Text) 
    In the second argument of ‘($)’, namely 
    ‘do { f <- param ("f" :: L.Text); 
      file "create.html" }’ 
    In a stmt of a 'do' block: 
    post "/create" 
    $ do { f <- param ("f" :: L.Text); 
      file "create.html" } 

答えて

4

paramは意味し、Parseable a => Text -> ActionM aを入力していますfのタイプはaです。しかし、fで何もしないので、aのタイプを推測する方法はありません。あなたは使用fを行うまでちょうど行をコメントにしたくないと仮定すると、あなたは明示的な型を提供する必要があります。

routes :: ScottyM() 
routes = do 
    post "/create" $ do 
    f <- param ("fa" :: L.Text) :: ActionM L.Text 
    file "create.html" 

おそらくParseableインスタンスを持っているいずれかのタイプを選ぶが、L.Text思えることができタイプはのようににする必要があります。実際にfを使用したら、明示的な注釈を削除することができます。

関連する問題