[Haskell-cafe] Using ClassyPrelude to handle either Text or ByteString

Mike Meyer mwm at mired.org
Fri May 8 20:10:51 UTC 2015


Ok, I can't seem to figure out how to make this work, and since I'm using
ClassyPrelude (from classy-prelude, latest version on hackage as of
yesterday), I think cafe is a better place to ask than beginners. Sorry if
this should have gone there.

I want to read in a list of files, concatenate them, and then run the
resulting data through a "process" function. So far, no problem. Given an
opts record that contains the list of files and some control for the
process function, this expression works:

hPut stdout =<< process opts . concat
<$> mapM (readFile . fpFromString) (files opts)

(BTW, recommendations on cleaning that up gratefully accepted)

However, I'd like to be able to read them all as either Text or ByteString,
depending on options being passed to me. This doesn't work so well. If I
give process a type of Text -> Text or ByteString->ByteString, everything
works fine with no other changes. However, any attempt to make it
polymorphic fails with ambiguous type warnings.

I've tried a slew of things, and found a few that work. But none of them
are what I'd call good, much less elegant. Is there a good way to do this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150508/c9204048/attachment.html>


More information about the Haskell-Cafe mailing list