Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Code golf (Tilmann) 2. Re: Code golf (Imants Cekusins) 3. Re: Code golf (Tilmann) 4. Re: Code golf (Marcin Mrotek) 5. Re: Code golf (Tilmann) 6. Code golf (Silent Leaf) ---------------------------------------------------------------------- Message: 1 Date: Thu, 19 May 2016 15:12:26 +0200 From: Tilmann <t_g...@gmx.de> To: Haskell Beginners <beginners@haskell.org> Subject: [Haskell-beginners] Code golf Message-ID: <875d19ea-7524-37ad-b475-68c7f4a36...@gmx.de> Content-Type: text/plain; charset=utf-8; format=flowed given: inputA :: IO String inputB :: IO String update :: String -> String -> IO () Is there an elegant way to refactor / code golf this: doIt :: IO () doIt = do a <- inputA b <- inputB update a b liftM2 doesn't work in this case.. Thank you! ------------------------------ Message: 2 Date: Thu, 19 May 2016 15:22:10 +0200 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Code golf Message-ID: <CAP1qinZr16mhYih3VCmO_WH0_+Cgs7JMeBfTU5aO-FfXs=r...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" if 'update' were changed to update :: [String] -> IO () then you could do: ?doIt :: IO () doIt = sequence [inputA,inputB] >>= update is this better? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160519/112445c3/attachment-0001.html> ------------------------------ Message: 3 Date: Thu, 19 May 2016 15:34:17 +0200 From: Tilmann <t_g...@gmx.de> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Code golf Message-ID: <856d279c-1e01-228a-0dcc-451578f7e...@gmx.de> Content-Type: text/plain; charset="utf-8"; Format="flowed" this is nice, thanks! What if a and b are of different types? I simplified my example to much.. Am 19.05.16 um 15:22 schrieb Imants Cekusins: > if 'update' were changed to > update :: [String] -> IO () > > then you could do: > ?doIt :: IO () > doIt = sequence [inputA,inputB] >>= update > > is this better? > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160519/4e597f43/attachment-0001.html> ------------------------------ Message: 4 Date: Thu, 19 May 2016 15:37:06 +0200 From: Marcin Mrotek <marcin.jan.mro...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Code golf Message-ID: <CAJcfPznFx3kcEJgnJEsmskA8fm+8WqRjoDB+NRd=jpyxuce...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello, What about "join $ update <$> a <*> b" ? Best regards, Marcin Mrotek -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160519/a12fc9ca/attachment-0001.html> ------------------------------ Message: 5 Date: Thu, 19 May 2016 16:03:57 +0200 From: Tilmann <t_g...@gmx.de> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Code golf Message-ID: <1b168c3f-d5b6-208c-8862-d9749e11e...@gmx.de> Content-Type: text/plain; charset="windows-1252"; Format="flowed" That's what I was looking for! I didn't know about join! Thank you! Am 19.05.16 um 15:37 schrieb Marcin Mrotek: > Hello, > > What about "join $ update <$> a <*> b" ? > > Best regards, > Marcin Mrotek > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160519/0247d0dd/attachment-0001.html> ------------------------------ Message: 6 Date: Fri, 20 May 2016 04:50:28 +0200 From: Silent Leaf <silent.le...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Code golf Message-ID: <cagfccjpx9cao9sry6rkfk8aq+te2dtxgfchykqeoykmso1x...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" The interesting bit is, the following function > \? ma mb -> join (pure ? <*> ma <*> mb) which i like to write as follows using ((&) = flip ($)) [infixl 1] > \? ma mb -> pure ? <*> ma <*> mb & join (but it's just personal taste) is very similar to (=<<), aka (flip (>>=)) except the first argument (here ?) has type (a -> b -> m c) instead of (a -> m b), and of course the lambda above takes an added argument too (mb). Some could call it "bind2" (even if it's the flipped version of (>>=) that is being generalized), and well, some do. For those interested, there are several options are available to import it (along possibly with some of its siblings), from several libraries. (List possibly non exhaustive.) http://hackage.haskell.org/package/prelude-generalize-0.4/docs/Prelude-Generalize.html#v:bind2 http://hackage.haskell.org/package/SimpleH-1.2/docs/Algebra-Monad.html#v:bind2 http://hackage.haskell.org/package/definitive-base-2.3/docs/Algebra-Monad-Base.html#v:bind2 your problem become btw then: > doIt = bind2 update a b -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160520/d8315a31/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 95, Issue 25 *****************************************