From brad73435 at gmail.com Tue Sep 12 00:45:43 2023 From: brad73435 at gmail.com (Brad Smith) Date: Mon, 11 Sep 2023 17:45:43 -0700 Subject: [Haskell-beginners] Beginner question. Message-ID: I just started working my way through a Haskell book... first time with functional programming. Mid way through the first chapter she's introducing point-free programming with a trivial example transitioning from not point-free... makeGreeting salutation person = salutation <> " " <> person to point free... makeGreeting' = (<>) . (<> " ") After a little playing with it... it seems to make sense. So I thought I'd try evolving from salutation and name to salutation, first, and last names. But, after a bit of tinkering, I haven't been able to make it work... I'm sure it's something simple (one way or the other)... any help would be appreciated! Brad -------------- next part -------------- An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Tue Sep 12 08:07:42 2023 From: sylvain at haskus.fr (Sylvain Henry) Date: Tue, 12 Sep 2023 10:07:42 +0200 Subject: [Haskell-beginners] Beginner question. In-Reply-To: References: Message-ID: Hi, https://pointfree.io/ gives: Input: f x y z = x <> " " <> y <> " " <> z Output: f = ((<>) .) . flip flip " " . ((<>) .) . (<>) . (<> " ") So no, it's not something simple! For clarity I would recommend using the non-point-free version, even in the case given in the book. Use point-free only in simple cases like `map (+ 1)` where the meaning is obvious. Sylvain On 12/09/2023 02:45, Brad Smith wrote: > I just started working my way through a Haskell book... first time > with functional programming. Mid way through the first chapter she's > introducing point-free programming with a trivial example > transitioning from not point-free... > > makeGreeting salutation person = salutation <> " " <> person > > to point free... > > makeGreeting' = (<>) . (<> " ") > > After a little playing with it... it seems to make sense. So I thought > I'd try evolving from salutation and name to salutation, first, and > last names. But, after a bit of tinkering, I haven't been able to make > it work... > > I'm sure it's something simple (one way or the other)... any help > would be appreciated! > > Brad > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From brad73435 at gmail.com Tue Sep 12 13:35:14 2023 From: brad73435 at gmail.com (brad73435 Smith) Date: Tue, 12 Sep 2023 06:35:14 -0700 Subject: [Haskell-beginners] Beginner question. In-Reply-To: References: Message-ID: <8E4007FD-FB45-43D8-9AA9-324F6C4C2CF1@gmail.com> That’s an impressive step in complexity! FWIW, for ‘f x y = x <> " " <> y’ that website gave the same result as the book… ‘f = (<>) . (<> " ")’… so it seems to do a good job of giving a simplified solution. Understood re only using point-free for simple, clear cases… though it was a good exercise for me to understand what’s going on with the function composition operator (.). Thank you! Brad Sent from my iPhone > On Sep 12, 2023, at 1:08 AM, Sylvain Henry wrote: > > Hi, > > https://pointfree.io/ gives: > > Input: f x y z = x <> " " <> y <> " " <> z > > Output: f = ((<>) .) . flip flip " " . ((<>) .) . (<>) . (<> " ") > > So no, it's not something simple! > > For clarity I would recommend using the non-point-free version, even in the case given in the book. Use point-free only in simple cases like `map (+ 1)` where the meaning is obvious. > > Sylvain > > >> On 12/09/2023 02:45, Brad Smith wrote: >> I just started working my way through a Haskell book... first time with functional programming. Mid way through the first chapter she's introducing point-free programming with a trivial example transitioning from not point-free... >> >> makeGreeting salutation person = salutation <> " " <> person >> >> to point free... >> >> makeGreeting' = (<>) . (<> " ") >> >> After a little playing with it... it seems to make sense. So I thought I'd try evolving from salutation and name to salutation, first, and last names. But, after a bit of tinkering, I haven't been able to make it work... >> >> I'm sure it's something simple (one way or the other)... any help would be appreciated! >> >> Brad >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners