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

Sibi sibi at psibi.in
Thu Sep 28 11:03:47 UTC 2017


It should be free instead of tree:

http://pointfree.io/

Regards,

On Thu, Sep 28, 2017 at 4:27 PM, Jeffrey Brown <jeffbrown.the at gmail.com>
wrote:

> > or, equivalently:
> >
> >        a `andthen` b = (>>) <$> a <*> b
> >
> > for which http://pointree.io dutifully gives me:
> >
> >      andthen = (<*>) . ((>>) <$>)
>
> That link is not working for me, and Google isn't finding it, and it
> sounds like a useful thing.
>
>
> On Thu, Sep 28, 2017 at 1:55 AM, Viktor Dukhovni <ietf-dane at dukhovni.org>
> wrote:
>
>>
>> When generating a report file from a database I found it much more
>> efficient (significantly shorter runtime) to represent each row
>> by an I/O action that prints the row, rather than to construct a
>> Row object that to print and throw away.
>>
>> But the naive way to construct the I/O action can be tedious to
>> maintain once the column count gets appreciably high:
>>
>>     newtype Foo = Foo { _foo :: IO () }
>>     instance FromRow Foo where
>>       fromRow = Foo <$> (rowPrinter <$> field <*> field <*> field <*> ...
>> <*> field)
>>         where
>>           rowPrinter :: Type1 -> Type2 -> Type3 -> ... -> TypeN -> IO ()
>>           rowPrinter p1 p2 p3 ... pN = do
>>             printP1
>>             printP2
>>             printP3
>>             ...
>>             printPN
>>
>> So I decided to applicatively decompose the rowPrinter function
>> (with the actual name of "andthen" to be determined later) as:
>>
>>    rowPrinter = (printP1 <$> field) `andthen`
>>                 (printP2 <$> field) `andthen`
>>                 (printP3 <$> field) `andthen`
>>                 ...
>>                 (printPN <$> field)
>>
>> which avoids the need to package the column printers explicitly into
>> a single function, and may be somewhat more efficient a well.
>>
>> What was not immediately obvious to me was whether there's an "off the
>> shelf" implementation of "andthen" I could just reuse. The necessary
>> operator satisfies:
>>
>>         andthen (f (m a)) (f (m b)) = f (ma >> mb)
>>
>> or, equivalently:
>>
>>         a `andthen` b = (>>) <$> a <*> b
>>
>> for which http://pointree.io dutifully gives me:
>>
>>        andthen = (<*>) . ((>>) <$>)
>>
>> Its type signature is:
>>
>>     Prelude> :set prompt "l> "
>>     l> :m + Control.Applicative
>>     l> :m + Control.Monad
>>     l> :t ((<*>) . ((>>) <$>))
>>     ((<*>) . ((>>) <$>))
>>       :: (Monad m, Applicative f) => f (m a) -> f (m b) -> f (m b)
>>     l>
>>
>> It seems to me that this would have been done before, and the operator
>> would already be present in some package, but I'm having trouble finding
>> it.
>>
>> (Due to the hidden constructors of FromRow defining a Semigroup does not
>>  work out here, so I can't use (<>), which also inconveniently conflicts
>>  with  Monoid (<>)).
>>
>> So my question is whether the operator in question is already available,
>> under some name in some package, or else suggested names for it if new.
>>
>> --
>>         Viktor.
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>
>
>
>
> --
> Jeff Brown | Jeffrey Benjamin Brown
> Website <https://msu.edu/~brown202/>   |   Facebook
> <https://www.facebook.com/mejeff.younotjeff>   |   LinkedIn
> <https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often
> miss messages here)   |   Github <https://github.com/jeffreybenjaminbrown>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>



-- 
Sibi, sibi at psibi.in
WWW: psibi.in <http://www.psibi.in>
Twitter/github/identi.ca: psibi
GPG Fingerpint: A241 B3D6 F4FD D40D D7DE B1C6 D19E 3E0E BB55 7613
Registered Linux User ID: 534664
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170928/2798cd4f/attachment.html>


More information about the Haskell-Cafe mailing list