Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/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. difference between . and $ (h...@nym.hush.com) 2. Re: difference between . and $ (Tom Murphy) 3. Re: difference between . and $ (Rafael Gustavo da Cunha Pereira Pinto) 4. Re: difference between . and $ (Chadda? Fouch?) 5. Re: difference between . and $ (A.M.) 6. Re: Stack space overflow: using strict accumulator still fails (Hugo Ferreira) ---------------------------------------------------------------------- Message: 1 Date: Sun, 30 Oct 2011 10:39:16 -0700 From: h...@nym.hush.com Subject: [Haskell-beginners] difference between . and $ To: beginners@haskell.org Message-ID: <20111030173917.091e5e6...@smtp.hushmail.com> Content-Type: text/plain; charset="UTF-8" Doesn't . and $ do the same thing? I always get confused about that, like when would I use one over the other. ------------------------------ Message: 2 Date: Sun, 30 Oct 2011 14:40:06 -0400 From: Tom Murphy <amin...@gmail.com> Subject: Re: [Haskell-beginners] difference between . and $ To: h...@nym.hush.com Cc: beginners@haskell.org Message-ID: <cao9q0tv9tompun-hssfzckfe-693symqvf-o6wsacw3ba3r...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" The short answer is no, they're not the same. Someone asked this exact question about a month ago, and there were some very good answer answers, but it's hard for me to find the thread. I can't find a search engine that'll let me search for keywords like "$" and ".". Anybody remember which thread this was? Tom / amindfv On Sun, Oct 30, 2011 at 1:39 PM, <h...@nym.hush.com> wrote: > Doesn't . and $ do the same thing? I always get confused about > that, like when would I use one over the other. > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111030/957d40c2/attachment-0001.htm> ------------------------------ Message: 3 Date: Sun, 30 Oct 2011 16:41:41 -0200 From: Rafael Gustavo da Cunha Pereira Pinto <rafaelgcpp.li...@gmail.com> Subject: Re: [Haskell-beginners] difference between . and $ To: h...@nym.hush.com Cc: beginners@haskell.org Message-ID: <cakeofdy0fm2qsvhvooyxwbers1+3x-fv_q2ud7m8gyrfbcd...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" No, not really the '.' operator is function composition, so f.g is a new function with f applied over g. h=f.g ==> h x = f ( g x ) the '$' is the apply operator, and it applies the right side to the left side: h = f $ x ==> h= f ( x ) You can check this looking at their types (.) :: (b -> c) -> (a -> b) -> a -> c ($) :: (a -> b) -> a -> b the first one takes two functions and return a new function. The second takes a function and a value and returns a value. Regards Rafael On Sun, Oct 30, 2011 at 15:39, <h...@nym.hush.com> wrote: > Doesn't . and $ do the same thing? I always get confused about > that, like when would I use one over the other. > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Rafael Gustavo da Cunha Pereira Pinto -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111030/bd4ad7f3/attachment-0001.htm> ------------------------------ Message: 4 Date: Sun, 30 Oct 2011 22:08:07 +0100 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] difference between . and $ To: h...@nym.hush.com Cc: beginners@haskell.org Message-ID: <canfjzrzzkrojkas3ufvatyo3mfq2pavndvdqz9o9prlfty-...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Sun, Oct 30, 2011 at 6:39 PM, <h...@nym.hush.com> wrote: > Doesn't . and $ do the same thing? ?I always get confused about > that, like when would I use one over the other. > It is true that there is some overlap, mainly when you have a big stack of one parameter functions to apply : > result = f $ g $ h $ x or > result = f . g . h $ x The second form is preferred though for the good reason that it is easier to refactor : You can take any part of the composition chain, pull it out and give it a name (or use it somewhere else) without worry : > result = newFun . h $ x > where newFun = f . g Whereas with the first form you'll need to introduce a point (which you'll have to name) and sometimes rework your expression : > result = newFun $ h $ x > where newFun y = f $ g $ y Anyway as for the difference : f $ g $ h $ x == f (g (h x)) In other words you apply a function to the results of another function itself applied to another function applied to the point x. f . g . h $ x == (f . g . h) x You create a new function that is the composition of the three initial ones then apply it to the point x. Of course in practice the same operation occurs in both cases but conceptually you're more "functional" and "modular" in the second formulation. -- Jeda? ------------------------------ Message: 5 Date: Sun, 30 Oct 2011 17:12:23 -0400 From: "A.M." <age...@themactionfaction.com> Subject: Re: [Haskell-beginners] difference between . and $ To: beginners@haskell.org Message-ID: <97d808df-b3b4-4942-bebf-a7acb2c82...@themactionfaction.com> Content-Type: text/plain; charset=us-ascii On Oct 30, 2011, at 1:39 PM, h...@nym.hush.com wrote: > Doesn't . and $ do the same thing? I always get confused about > that, like when would I use one over the other. One good way to answer questions like this for yourself is to jump to the source. By looking at the type in ghci ":t (.)", I found that (.) if defined in GHC.Base. I downloaded the "base" git repo (http://darcs.haskell.org/packages/base.git/) because the online docs for GHC.Base are linked but the link is broken (http://hackage.haskell.org/packages/archive/base/4.4.0.0/doc/html/GHC-Base.html) and found the following: GHC/Prelude.lhs {-# INLINE (.) #-} -- Make sure it has TWO args only on the left, so that it inlines -- when applied to two functions, even if there is no final argument (.) :: (b -> c) -> (a -> b) -> a -> c (.) f g = \x -> f (g x) infixr 0 $ ... {-# INLINE ($) #-} ($) :: (a -> b) -> a -> b f $ x = f x So, we see that (.) returns a lambda of a simple nested function call while ($) is compiled away to perform no extra steps. They are similar in that Haskellers often use them to reduce parentheses but different in their outcomes. In particular, note the difference in types- (.) takes two function arguments while ($) takes only one. I am a beginner myself and I often find Haskell modules lightly documented (especially in comparison to more widely-used languages), so I find jumping to the source invaluable. Cheers, M ------------------------------ Message: 6 Date: Mon, 31 Oct 2011 09:36:53 +0000 From: Hugo Ferreira <h...@inescporto.pt> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <4eae6c35.5000...@inescporto.pt> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Hello, Apologies for the late reply but I had to prep the code. On 10/28/2011 09:43 AM, Daniel Fischer wrote: > On Thursday 27 October 2011, 17:02:46, Hugo Ferreira wrote: >> But something seems to be wrong here. If I do: >> >> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs >> where scoreElem r s z = >> let (nCorrect, nIncorrect) = s in >> case ruleApplication r z of >> Just tag -> if tag == correct >> then (nCorrect+1, nIncorrect) >> else (nCorrect, nIncorrect+1) >> Nothing -> (nCorrect, nIncorrect) >> where c = Z.cursor z >> (correct,_) = c >> >> it works correctly, however this does not work: >> >> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs >> where scoreElem r (!nCorrect, !nIncorrect) z = >> case ruleApplication r z of >> Just tag -> if tag == correct >> then (nCorrect+1, nIncorrect) >> else (nCorrect, nIncorrect+1) >> Nothing -> (nCorrect, nIncorrect) >> where c = Z.cursor z >> (correct,_) = c >> >> I have been staring at this for some time now, but cannot >> understand why it does not work. Any ideas? > > No. Looks perfectly okay (well, the indentation is wrong, but that's the > same for the working version above and is probably due to the mail client). Not really. That's pretty much the indentation I am using. I actually had additional trace statements. Can you please tell me what's wrong? > Can you post the complete source for diagnosis? > I have attached the code + cabal files. I think that is all that is required. I am not sending the training data because it is too large (+7 Mega bytes). That is available at http://nlpwp.org/nlpwp-data.zip TIA, Hugo F. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: postagger.cabal URL: <http://www.haskell.org/pipermail/beginners/attachments/20111031/dc575a5a/attachment.asc> -------------- next part -------------- A non-text attachment was scrubbed... Name: Setup.lhs Type: text/x-literate-haskell Size: 110 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20111031/dc575a5a/attachment.lhs> -------------- next part -------------- A non-text attachment was scrubbed... Name: Main.hs Type: text/x-haskell Size: 14242 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20111031/dc575a5a/attachment.hs> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 40, Issue 48 *****************************************