Given the following code:
import Data.Attoparsec.Text
import qualified Conduit as C
import qualified Data.Conduit.Combinators as CC
f :: FilePath -> FilePath -> IO ()
f infile outfile =
runResourceT $
CC.sourceFile infile $$ C.encodeUtf8C =$= x
where x's type is ConduitM Text Void (ResourceT IO) ()
The following compile-time error occurs in my private github repo:
• No instance for (mono-traversable-1.0.2:Data.Sequences.Utf8
ByteString Text)
arising from a use of ‘C.encodeUtf8C’
• In the first argument of ‘(=$=)’, namely ‘C.encodeUtf8C’
In the second argument of ‘($$)’, namely ‘C.encodeUtf8C =$= x’
In the second argument of ‘($)’, namely
‘CC.sourceFile infile $$ C.encodeUtf8C =$= x’
How can I resolve this compile-time error?
EDIT
My understanding of the types:
> :t sourceFile
sourceFile
:: MonadResource m =>
FilePath
-> ConduitM
i bytestring-0.10.8.1:Data.ByteString.Internal.ByteString m ()
> :t ($$)
($$) :: Monad m => Source m a -> Sink a m b -> m b
> :t Conduit
type Conduit i (m :: * -> *) o = ConduitM i o m ()
> :i Source
type Source (m :: * -> *) o = ConduitM () o m ()
> :i Sink
type Sink i = ConduitM i Data.Void.Void :: (* -> *) -> * -> *
> :t (=$=)
(=$=)
:: Monad m => Conduit a m b -> ConduitM b c m r -> ConduitM a c m r
C.encodeUtf8C =$= x boils down to, I think:
(mono-traversable-1.0.2:Data.Sequences.Utf8 text binary,
Monad m) =>
Conduit text m binary ()
=$=
ConduitM Text Void binary ()
yielding a return type of
ConduitM text Void (ResourceT IO) ()
And I suppose that this type, i.e. C.encodeUtf8C =$= x, does not unify to the expected second argument of CC.sourceFile?
Utf8 Text ByteString. Is something flipped around here? Do you actually needdecodeinstead? I'm not super familiar with conduit, but what direction does your last line flow (right to left or left to right)? - Bartek Banachewiczghc-pkg list bytestringandghc-pkg list mono-traversable. Also, what version of ghc are you using? Newer one should produce better error message in such cases. - Yuras$ghc-pkg list bytestring /usr/local/Cellar/ghc/8.0.1_4/lib/ghc-8.0.1.20161213/package.conf.d bytestring-0.10.8.1 $ghc-pkg list mono-traversable /usr/local/Cellar/ghc/8.0.1_4/lib/ghc-8.0.1.20161213/package.conf.d. How do I tell whichGHCI'm using on thisstackproject? - Kevin Meredith