我将运算符<|>
用于:
import qualified Data.ByteString.Lazy as B
import Network.HTTP.Conduit (simpleHttp)
import Data.Aeson
import Data.Maybe
data FooBar = FooBar {
name :: !Text,
surname :: !Text
} deriving (Show,Generic)
instance FromJSON FooBar
instance ToJSON FooBar
getFeed :: String -> String -> IO (FooBar)
getFeed foo bar = decode <$> (B.readFile foo <|> simpleHttp bar)
但是当我尝试编译它时,我得到:
No instance for (Alternative IO) arising from a use of ‘<|>’
In the second argument of ‘(<$>)’, namely
‘(B.readFile foo <|> simpleHttp bar)’
In the expression:
decode <$> (B.readFile foo <|> simpleHttp bar)
In an equation for ‘getFeed’:
getFeed env id
= decode <$> (B.readFile foo <|> simpleHttp bar)
这个错误对我来说有点模糊。知道如何解决吗?(顺便说一句,从这个回复中得到一些见解:对“替代”类型类的含义及其与其他类型类的关系感到困惑)