[Haskell-cafe] Readable Haskell

Viktor Dukhovni ietf-dane at dukhovni.org
Sun Sep 20 23:15:52 UTC 2020


On Sun, Sep 20, 2020 at 08:37:28PM +0200, MarLinn wrote:

> >      main :: IO ()
> >      main = Q.getContents           -- raw bytes
> >             & AS.parsed lineParser  -- stream of parsed `Maybe Int`s; blank lines are `Nothing`
> >             & void                  -- drop any unparsed nonsense at the end -- [1]
> >             & S.split Nothing       -- split on blank lines
> >             & S.maps S.concat       -- keep `Just x` values in the sub-streams (cp. catMaybes)
> >             & S.mapped S.sum        -- sum each substream
> >             & S.print               -- stream results to stdout
> 
> There's still quite a bit that can be improved here.

Yes, that short example (from a module's documentation) was chosen to
illustrate left-to-right style, and the direct use of helper functions
from `streaming` also helps to illustrate those functions in use.  So in
the context of module documentation, it is actually helpful to not
replace the helpers with semantically appropriate (but implementation
opaque) aliases.

As for objections to use of left to right notation, in representing
chains of transformations, we're going to have to disagree about that.

-- 
    Viktor.


More information about the Haskell-Cafe mailing list