類似しているが全く同じではないエラーをいくつか検索した後で、この問題をデバッグする際に次のステップに進むことができません。 this Haskell scriptPandoc returnedどちらかのタイプ
import Text.Pandoc (writePlain, readHtml, def, pandocVersion)
convert :: String -> String
convert = writePlain def . readHtml def
から
関連する行は、このエラーが発生しています:
Main.hs:11:28: error:
• Couldn't match type ‘Either
Text.Pandoc.Error.PandocError Text.Pandoc.Definition.Pandoc’
with ‘Text.Pandoc.Definition.Pandoc’
Expected type: String -> Text.Pandoc.Definition.Pandoc
Actual type: String
-> Either
Text.Pandoc.Error.PandocError Text.Pandoc.Definition.Pandoc
• In the second argument of ‘(.)’, namely ‘readHtml def’
In the expression: writePlain def . readHtml def
In an equation for ‘convert’:
convert = writePlain def . readHtml def
環境の詳細:
- GHC 8.0.1
- カバル1.24 と4.10.9
がcabal install
をされてたのx
答えるためのおかげで、コメントや壁に頭をバッシングの数時間を」:
import Network.HTTP.Conduit (simpleHttp)
import Data.Text.Lazy as TL
import Data.Text.Lazy.Encoding as TLE
import Text.Pandoc
import Text.Pandoc.Error
import Data.Set
htmlToPlainText :: String -> String
htmlToPlainText = writePlain (def {
writerExtensions = Data.Set.filter (/= Ext_raw_html) (writerExtensions def)
}) . handleError . readHtml def
main :: IO()
main = do
response <- simpleHttp "https://leonstafford.github.io"
let body = TLE.decodeUtf8 (response)
let bodyAsString = TL.unpack (body)
putStrLn $ htmlToPlainText bodyAsString
'convert'の型シグネチャを' String - > PandocError Strings 'に変更したほうがよいので、この 'convert'関数の呼び出し側はエラーに反応するための妥当な手順をとることができます。型システムは、 'String - > String'がこの関数の良い型ではないことを警告しようとしています。さらなる証拠:あなたは 'show'を 'Left'の場合に書かなければなりませんでしたが、これは明らかにこの関数の良い結果ではありません。 – amalloy