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. foldr point free notation (Alexander Chen) 2. Re: foldr point free notation (Bob Ippolito) 3. Re: foldr point free notation (Apoorv Ingle) 4. Why do i need to take out the list for this to work (Alexander Chen) 5. Re: Why do i need to take out the list for this to work (Bob Ippolito) ---------------------------------------------------------------------- Message: 1 Date: Wed, 10 Jun 2020 16:49:05 +0200 (CEST) From: Alexander Chen <alexan...@chenjia.nl> To: beginners@haskell.org Subject: [Haskell-beginners] foldr point free notation Message-ID: <514947741.528496.1591800545...@ichabod.co-bxl> Content-Type: text/plain; charset="utf-8" hi, --any function foldr myAny'' :: (a-> Bool) -> [a] -> Bool myAny'' f = foldr (\a b -> f a || b) False this is the foldr notions. How would i make this point free? best, -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200610/ae48ec95/attachment-0001.html> ------------------------------ Message: 2 Date: Wed, 10 Jun 2020 08:00:34 -0700 From: Bob Ippolito <b...@redivi.com> To: Alexander Chen <alexan...@chenjia.nl>, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] foldr point free notation Message-ID: <cacwmpm_n4k9ocesmgf2uvsmkvgvff0lzwo53y-xtaw-j4vw...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" The better question is why would you want to? If you could even manage, the result would be practically incomprehensible. On Wed, Jun 10, 2020 at 07:49 Alexander Chen <alexan...@chenjia.nl> wrote: > hi, > > --any function foldr > myAny'' :: (a-> Bool) -> [a] -> Bool > myAny'' f = foldr (\a b -> f a || b) False > > this is the foldr notions. How would i make this point free? > > best, > _______________________________________________ > 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/20200610/f82d7e70/attachment-0001.html> ------------------------------ Message: 3 Date: Wed, 10 Jun 2020 10:50:27 -0500 From: Apoorv Ingle <apoorv.in...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] foldr point free notation Message-ID: <bb82de01-f366-4125-8a67-9f730f9bd...@gmail.com> Content-Type: text/plain; charset="utf-8" Hi Alexander, I found this tool online[1], that converts your function to a point free style. myAny'' f = foldr (\a b -> f a || b) False is transformed to myAny'' = flip foldr False . ((||) .) Again as Bob mentions, the point free style comes at a cost of unreadability and hence unmaintainable. Cheers! Apoorv [1]: http://pointfree.io/ <http://pointfree.io/> > On Jun 10, 2020, at 10:00, Bob Ippolito <b...@redivi.com> wrote: > > The better question is why would you want to? If you could even manage, the > result would be practically incomprehensible. > > On Wed, Jun 10, 2020 at 07:49 Alexander Chen <alexan...@chenjia.nl > <mailto:alexan...@chenjia.nl>> wrote: > hi, > > --any function foldr > myAny'' :: (a-> Bool) -> [a] -> Bool > myAny'' f = foldr (\a b -> f a || b) False > > this is the foldr notions. How would i make this point free? > > best, > _______________________________________________ > Beginners mailing list > Beginners@haskell.org <mailto:Beginners@haskell.org> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners> > _______________________________________________ > 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/20200610/806d3461/attachment-0001.html> ------------------------------ Message: 4 Date: Wed, 10 Jun 2020 20:42:12 +0200 (CEST) From: Alexander Chen <alexan...@chenjia.nl> To: beginners@haskell.org Subject: [Haskell-beginners] Why do i need to take out the list for this to work Message-ID: <1276054988.546547.1591814532...@ichabod.co-bxl> Content-Type: text/plain; charset="utf-8" hi, assigment: make your own element function with the any function. --elem with any myElemAny :: Eq a => a -> [a] -> Bool myElemAny a = any (== a) --elem with any myElemAny' :: Eq a => a -> [a] -> Bool myElemAny' a [x]= any (== a) [x] myElemAny' compiles but throws an error because it has a non-exhaustive pattern. Could somebody tell me why the list gives the function grieveness? thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200610/051290ca/attachment-0001.html> ------------------------------ Message: 5 Date: Wed, 10 Jun 2020 11:49:48 -0700 From: Bob Ippolito <b...@redivi.com> To: Alexander Chen <alexan...@chenjia.nl>, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Why do i need to take out the list for this to work Message-ID: <cacwmpm-qpjurnbegexg8n0lm1tyj_pigco0mdit2hrenckx...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Square brackets [] are pattern match syntax for lists. This will only work for lists of length 1, anything else will be an error. Get rid of the brackets on both sides of the equation and it will do what you expect. Typically list variables are given plural names, such as xs instead of x. On Wed, Jun 10, 2020 at 11:42 Alexander Chen <alexan...@chenjia.nl> wrote: > hi, > > assigment: make your own element function with the any function. > > --elem with any > myElemAny :: Eq a => a -> [a] -> Bool > myElemAny a = any (== a) > > --elem with any > myElemAny' :: Eq a => a -> [a] -> Bool > myElemAny' a [x]= any (== a) [x] > > > myElemAny' compiles but throws an error because it has a non-exhaustive > pattern. Could somebody tell me why the list gives the function grieveness? > > thanks, > > _______________________________________________ > 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/20200610/3b040bed/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 144, Issue 2 *****************************************