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. Clarifying $ vs parentheses (Josh Friedlander) 2. Re: Clarifying $ vs parentheses (Bob Ippolito) 3. Re: Clarifying $ vs parentheses (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Thu, 20 Aug 2020 22:02:21 +0300 From: Josh Friedlander <joshuatfriedlan...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Clarifying $ vs parentheses Message-ID: <cac2wd73m1h9skgoljjnp4usvt0t4mxvhye9qkbukv4p6gdm...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I understand that in general $ is a) right-associative and b) lowest-priority. But if so shouldn't these two be roughly the same? λ take (succ 10) $ cycle "hello world" "hello world" But not this? λ take $ succ 10 $ cycle "hello world" <interactive>:20:8: error: • No instance for (Enum ([Char] -> Int)) arising from a use of ‘succ’ (maybe you haven't applied a function to enough arguments?) • In the expression: succ 10 In the second argument of ‘($)’, namely ‘succ 10 $ cycle "hello world"’ In the expression: take $ succ 10 $ cycle "hello world" <interactive>:20:13: error: • No instance for (Num ([Char] -> Int)) arising from the literal ‘10’ (maybe you haven't applied a function to enough arguments?) • In the first argument of ‘succ’, namely ‘10’ In the expression: succ 10 In the second argument of ‘($)’, namely ‘succ 10 $ cycle "hello world"’ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200820/60226e97/attachment-0001.html> ------------------------------ Message: 2 Date: Thu, 20 Aug 2020 12:36:24 -0700 From: Bob Ippolito <b...@redivi.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Clarifying $ vs parentheses Message-ID: <cacwmpm9wuu-6okwxqtit8ulad-rvnikskzgncttb-zuz1vd...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Because the second one is: take (succ 10 (cycle “hello world”)) On Thu, Aug 20, 2020 at 12:03 Josh Friedlander <joshuatfriedlan...@gmail.com> wrote: > I understand that in general $ is a) right-associative and b) > lowest-priority. But if so shouldn't these two be roughly the same? > > λ take (succ 10) $ cycle "hello world" > "hello world" > > But not this? > λ take $ succ 10 $ cycle "hello world" > > <interactive>:20:8: error: > • No instance for (Enum ([Char] -> Int)) > arising from a use of ‘succ’ > (maybe you haven't applied a function to enough arguments?) > • In the expression: succ 10 > In the second argument of ‘($)’, namely > ‘succ 10 $ cycle "hello world"’ > In the expression: take $ succ 10 $ cycle "hello world" > > <interactive>:20:13: error: > • No instance for (Num ([Char] -> Int)) > arising from the literal ‘10’ > (maybe you haven't applied a function to enough arguments?) > • In the first argument of ‘succ’, namely ‘10’ > In the expression: succ 10 > In the second argument of ‘($)’, namely > ‘succ 10 $ cycle "hello world"’ > > > _______________________________________________ > > 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/20200820/0697da5d/attachment-0001.html> ------------------------------ Message: 3 Date: Thu, 20 Aug 2020 21:40:31 +0200 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Clarifying $ vs parentheses Message-ID: <20200820194031.GA30551@extensa> Content-Type: text/plain; charset=utf-8 Hello Josh, il 20 agosto 2020 alle 22:02 josh friedlander ha scritto: > i understand that in general $ is a) right-associative and b) > lowest-priority. but if so shouldn't these two be roughly the same? > > λ take (succ 10) $ cycle "hello world" > "hello world" > > But not this? > λ take $ succ 10 $ cycle "hello world" > > […] λ> :info ($) ($) :: (a -> b) -> a -> b -- Defined in ‘GHC.Base’ infixr 0 $ So, since `$` is right associative, the expression take $ succ 10 $ cycle "hello world" becomes take (succ 10 (cycle "hello world")) `cycle "hello world"` makes sense, `succ 10` makes sense, `succ 10 anotherArgument` does not. Even `take someStuff` is probably not what you want, since take is usually invoked with two arguments. A useful intuition when you see ($) is `it will evaluate everything on the right of it first`. This way, `not $ xx yy zz` looks right, `take $ xx aa yy qq` less so. Does this help? —F ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 146, Issue 7 *****************************************