I am using the operator <|>
for:
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)
But when I try to compile it I get:
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)
The error is a bit obscure to me. Any idea how to fix that? (BTW some insight from this reply: Confused by the meaning of the 'Alternative' type class and its relationship to other type classes)