[Haskell-cafe] Help requested: naming things in conduit
michael at snoyman.com
Thu Jun 28 19:11:26 CEST 2012
I'm just about ready to make the 0.5 release of conduit. And as usual,
I'm running up against the hardest thing in programming: naming
Here's the crux of the matter: in older versions of conduit, functions
would have a type signature of Source, Sink, or Conduit. For example:
sourceFile :: MonadResource m => FilePath -> Source m ByteString
I think most people can guess at what this function does: it produces
a stream of ByteStrings, which are read from the given file.
Now the trick: Source (and Sink and Conduit) are all type synonyms
wrapping around the same type, Pipe. Ideally, we'd like to be able to
reuse functions like sourceFile in other contexts, such as producing a
Conduit that calls sourceFile. However, the type synonym Source
over-specifies some of the type parameters to Pipe, and therefore
`sourceFile` can't be used directly to create a Conduit.
To get around this whole problem, I've added a number of type synonyms
with rank-2 types, that don't over-specify. You can see the type
synonyms here, and more explanation of the problem here. So my
question is: can anyone come up with better names for these synonyms?
Just to summarize here:
* All of the generalized types start with a G, e.g., Source becomes GSource.
* For Sinks and Conduits, if leftovers are generated, there's an L
after the G (e.g., GLSink).
* For Sinks and Conduits which consume all of their input and then
return the upstream result, we tack on an Inf for Infinite (e.g.,
I think these names are relatively descriptive, and certain `GSink
ByteString m Int` is easier to follow than `Pipe l ByteString o u m
Int`, but I was wondering if anyone had some better recommendations.
 For example, maybe we want to produce `conduitFiles ::
MonadResource m => Conduit FilePath m ByteString`
 This problem exists to a smaller extent in conduit 0.4. This is
the purpose of the sinkToPipe function.
More information about the Haskell-Cafe