[Haskell-cafe] Reinventing the wheel? Does any existing package provide an applicatively lifted (>>) ?

Viktor Dukhovni ietf-dane at dukhovni.org
Thu Sep 28 16:56:48 UTC 2017


> On Sep 28, 2017, at 5:44 AM, Isaac Elliott <isaace71295 at gmail.com> wrote:
> 
> If you're not actually the Monad instance of IO,

Can you explain that qualification?

> then `andThen` is (*>) for `Compose RowParser IO a` (https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Functor-Compose.html).
> 
> So `rowPrinter` would be
> 
> rowPrinter =
>   getCompose $
>   Compose (printP1 <$> field) *>
>   Compose (printP2 <$> field) *>
>   ...
>   Compose (printPn <$> field)
> 
> It's a bit more verbose, but I think it's the best answer.

Indeed this works, and looks more clear than some new unfamiliar operator.
This seems to have no measurable run-time cost.  Is it reasonable to expect
that under the covers no objects boxed as (Compose _) are ever created, and
that Compose here is just compile-time syntactic sugar for applying (*>) at
the desired layer, so that:

   getCompose $ Compose (Foo Bar a)
             *> Compose (Foo Bar b)
             *> Compose (Foo Bar c)
             ...
             *> Compose (Foo Bar z)

just compiles down to Foo (Bar a *> Bar b *> Bar c *> ... *> Bar z)?
Where, in my case, Foo is "RowParser" and Bar is IO?

-- 
	Viktor.



More information about the Haskell-Cafe mailing list