[Haskell-cafe] Help requested: naming things in conduit

Michael Snoyman michael at snoyman.com
Thu Jun 28 19:11:26 CEST 2012


Hi all,

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
things.

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[1]. 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[2].

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[3], and more explanation of the problem here[4]. 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.,
GInfConduit, GLInfSink).

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.

Michael

[1] For example, maybe we want to produce `conduitFiles ::
MonadResource m => Conduit FilePath m ByteString`
[2] This problem exists to a smaller extent in conduit 0.4. This is
the purpose of the sinkToPipe function.
[3] https://github.com/snoyberg/conduit/blob/52d7bc0b551b877de92be4c87f933e3ffb1bb9f6/conduit/Data/Conduit/Internal.hs#L132
[4] https://github.com/snoyberg/conduit/blob/a853141d7b9eed047c7cc790979f73a346740ea0/conduit/Data/Conduit.hs#L403



More information about the Haskell-Cafe mailing list