Zulip Chat Archive

Stream: Is there code for X?

Topic: list operation


view this post on Zulip Kenny Lau (Jul 04 2020 at 16:58):

Is there a function that sends the lists [a,b,c] and [d,e,f] to [a*d, a*e, a*f, b*d, b*e, b*f, c*d, c*e, c*f] given any binary operator *?

view this post on Zulip Kenny Lau (Jul 04 2020 at 17:01):

something like (L.product M).map (function.uncurry (*))

view this post on Zulip Chris Hughes (Jul 04 2020 at 18:14):

zip_with?

view this post on Zulip Chris Hughes (Jul 04 2020 at 18:14):

No that's different actually.

view this post on Zulip David Wärn (Jul 04 2020 at 19:09):

This is a job for control theory

def foo {α β γ} (f : α  β  γ) (as : list α) (bs : list β) : list γ := f <$> as <*> bs
#reduce foo (+) [0, 1, 2] [10, 20, 30] -- [10, 20, 30, 11, 21, 31, 12, 22, 32]

view this post on Zulip Scott Morrison (Jul 05 2020 at 00:11):

Surely something like do a <- L, b <- M, return a*b works, and requires understanding fewer hieroglyphics. (Not at a computer, didn't test.)

view this post on Zulip Simon Hudon (Jul 05 2020 at 00:16):

It does work too. It uses the monad structure on list where as @David Wärn's solution only requires an applicative functor

view this post on Zulip Bhavik Mehta (Jul 05 2020 at 15:16):

Should we port ApplicativeDo to lean :big_smile:

view this post on Zulip Simon Hudon (Jul 05 2020 at 18:08):

I wonder if we can implement that as a library


Last updated: May 17 2021 at 16:26 UTC