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. IO question (Rustom Mody) 2. Re: Stack space overflow: using strict accumulator still fails (Hugo Ferreira) 3. Re: IO question (Ertugrul Soeylemez) 4. Re: IO question (Thomas Davie) 5. Re: IO question (Daniel Fischer) 6. Re: IO question (Rustom Mody) 7. Re: IO question (Brandon Allbery) 8. Re: Need some advices about university (Noah Diewald) ---------------------------------------------------------------------- Message: 1 Date: Thu, 27 Oct 2011 20:18:44 +0530 From: Rustom Mody <rustompm...@gmail.com> Subject: [Haskell-beginners] IO question To: beginners <beginners@haskell.org> Message-ID: <CAJ+TeodCmOc=Bxs_4QejnoKknRq0v8JyS4=bz0r+k0csfdf...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I have this from Peyton Jones awkward squad paper getTwoChars :: IO (Char,Char) getTwoChars = do c1 <- getChar c2 <- getChar return (c1,c2) Can someone explain what is happening here? *Main> getTwoChars ab ('a','b') *Main> getTwoChars a ('\n','a') -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111027/42ef6b50/attachment-0001.htm> ------------------------------ Message: 2 Date: Thu, 27 Oct 2011 16:02:46 +0100 From: Hugo Ferreira <h...@inescporto.pt> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: beginners@haskell.org Message-ID: <4ea97296.5000...@inescporto.pt> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Daniel, On 10/27/2011 03:26 PM, Daniel Fischer wrote: > On Thursday 27 October 2011, 15:44:34, Hugo Ferreira wrote: >> My apologies, the 2nd function should be: >> >> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs >> where scoreElem r s@(nCorrect, nIncorrect) z = >> case ruleApplication r z of >> Just tag -> if tag == correct then >> let nCorrect = nCorrect + 1 in > > This is a cyclic definition. The nCorrect on the right hand side is not the > nCorrect from the function parameter but the nCorrect from the left hand > side of the definition, so you have a nonterminating value here. > You need to introduce a new name, > > let newCorrect = nCorrect + 1 > in newCorrect `seq` (newCorrect, nIncorrect) > That was unexpected. I assumed a new variable with the same name. > (since nIncorrect isn't changed, we don't need to use seq on that). > Ok. Understood. 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? Regards, Hugo F. >> nCorrect `seq` nIncorrect `seq` >> (nCorrect, nIncorrect) >> else let nIncorrect = nIncorrect + 1 in > > Same problem here. > >> nCorrect `seq` nIncorrect `seq` >> (nCorrect, nIncorrect) >> Nothing -> s >> where (correct, _) = Z.cursor z >> >> R, >> Hugo F. >> >> On 10/27/2011 02:22 PM, Hugo Ferreira wrote: >>> Hello, >>> >>> After trying the suggestions, I still cannot execute >>> the code. I have tried: >>> >>> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs >>> where scoreElem r !s@(!nCorrect, !nIncorrect) z = >>> case ruleApplication r z of >>> Just tag -> if tag == correct then >>> (nCorrect+1, nIncorrect) >>> else (nCorrect, nIncorrect + 1) >>> Nothing -> s >>> where (correct, _) = Z.cursor z > > That should run, what's the problem here? > Perhaps the bangs should be placed s@(!(InCorrect, !nIncorrect)), I'm not > sure how ghc treats bang patterns exactly atm. > >>> >>> and >>> >>> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs >>> nIncorrect) >>> where (correct, _) = Z.cursor z >>> nCorrect = nCorrect + 1 >>> nIncorrect = nIncorrect + 1 > > Again cyclic definitions. > >>> where scoreElem r s@(nCorrect, nIncorrect) z = >>> case ruleApplication r z of >>> Just tag -> if tag == correct then >>> let nCorrect = nCorrect + 1 in >>> nCorrect `seq` nIncorrect `seq` (nCorrect, nIncorrect) >>> else let nIncorrect = nIncorrect + 1 in >>> nCorrect `seq` nIncorrect `seq` (nCorrect, nIncorrect) >>> Nothing -> s >>> where (correct, _) = Z.cursor z > > Here too. > >>> >>> >>> In an attempt to figure out the problem I also tried: >>> >>> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs >>> where scoreElem r !s@(!nCorrect, !nIncorrect) z = (nCorrect, >>> nIncorrect) where (correct, _) = Z.cursor z >>> nCorrect = nCorrect + 1 >>> nIncorrect = nIncorrect + 1 >>> >>> Strangely enough GHC complains that correct, nCorrect and nIncorrect >>> are not used. > > With -Wall or -fwarn-name-shadowing it should also complain about the > shadowing of nCorrect and nIncorrect. > >>> Why is this so for nCorrect and nIncorrect? Why won't >>> the above also execute in a strict manner? >>> >>> Does anyone have any ideas why I still get stack-overflow? >>> >>> TIA, >>> Hugo F. > ------------------------------ Message: 3 Date: Thu, 27 Oct 2011 17:04:50 +0200 From: Ertugrul Soeylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] IO question To: beginners@haskell.org Message-ID: <20111027170450.58374...@angst.streitmacht.eu> Content-Type: text/plain; charset=US-ASCII Rustom Mody <rustompm...@gmail.com> wrote: > I have this from Peyton Jones awkward squad paper > > getTwoChars :: IO (Char,Char) > getTwoChars = do > c1 <- getChar > c2 <- getChar > return (c1,c2) > > Can someone explain what is happening here? > *Main> getTwoChars > ab > ('a','b') This seems perfectly fine. The getTwoChars action is one that will result in a 2-tuple of Chars, when run. The getChar action is a value of type IO Char, so it's an action that, when run, yields a Char. While defining an IO action like getTwoChars you can use other actions to build it. In the context of IO each action is executed in sequence (the two getChars) you have there, and the "<-" arrow is used to give their results a name, if you care about them. The "return x" action is just the action, which will yield x when run, so "return (c1, c2)" will yield the tuple in conformance to getTwoChar's type. > *Main> getTwoChars > a > ('\n','a') This one seems really odd. Assuming that you typed "a" and then pressed the Return key, I don't know why it happens for you. For me it doesn't happen. I get the expected ('a', '\n'). Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ ------------------------------ Message: 4 Date: Thu, 27 Oct 2011 16:08:31 +0100 From: Thomas Davie <tom.da...@gmail.com> Subject: Re: [Haskell-beginners] IO question To: Rustom Mody <rustompm...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <c6a83696-dc70-4d08-86b9-604d42b8f...@gmail.com> Content-Type: text/plain; charset="windows-1252" The issue you're hitting I believe is two fold: 1) stdin has line buffering turned on. This means that the first example does not run until return is pressed because the input is not sent to ghci until then. 2) You now have a 3rd character on stdin that's yet to be consumed ? a new line character, this causes getTwoChars to grab that, and the following character when it's run a second time. You could solve this by turning off buffering on stdin, or by making getTwoChars ignore new lines. Bob if (*ra4 != 0xffc78948) { return false; } On 27 Oct 2011, at 15:48, Rustom Mody wrote: > I have this from Peyton Jones awkward squad paper > > getTwoChars :: IO (Char,Char) > getTwoChars = do > c1 <- getChar > c2 <- getChar > return (c1,c2) > > Can someone explain what is happening here? > *Main> getTwoChars > ab > ('a','b') > *Main> getTwoChars > a > ('\n','a') > _______________________________________________ > 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/20111027/78168f9d/attachment-0001.htm> ------------------------------ Message: 5 Date: Thu, 27 Oct 2011 17:11:39 +0200 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] IO question To: beginners@haskell.org Message-ID: <201110271711.40044.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Thursday 27 October 2011, 16:48:44, Rustom Mody wrote: > I have this from Peyton Jones awkward squad paper > > getTwoChars :: IO (Char,Char) > getTwoChars = do > c1 <- getChar > c2 <- getChar > return (c1,c2) > > Can someone explain what is happening here? > *Main> getTwoChars > ab > ('a','b') > *Main> getTwoChars > a > ('\n','a') Hmm, here I get Prelude> let getTwoChars :: IO (Char, Char); getTwoChars = do { x <- getChar; y <- getChar; return (x,y); } Prelude> getTwoChars ab('a','b') Prelude> getTwoChars ac('a','c') Prelude> Since your result pair appears on a different line, it seems that your input stream is line buffered and you have to press <Return> to make the input available to getChar. Then the entered newline isn't removed by the first getTwoChars, so it becomes the first Char gotten by the second invocation of getTwoChars. What's your OS and ghc version? ------------------------------ Message: 6 Date: Thu, 27 Oct 2011 21:07:52 +0530 From: Rustom Mody <rustompm...@gmail.com> Subject: Re: [Haskell-beginners] IO question To: beginners@haskell.org Message-ID: <caj+teofm5-yu3r_qozgm99ck8zx_mqyvmdqt7zcd-brwp1x...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Ok... Seems to only happen inside emacs (inf-haskell mode) At a shell it is as expected: *Main> getTwoChars a ('a','\n') So I guess its an emacs (comint-mode derivative to inferior process) issue. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111027/ddaad117/attachment-0001.htm> ------------------------------ Message: 7 Date: Thu, 27 Oct 2011 15:26:27 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] IO question To: Rustom Mody <rustompm...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <cakfcl4wj8vicxkxoxxp8usny7guddjqgqvwgnfnmjhfpxba...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Thu, Oct 27, 2011 at 10:48, Rustom Mody <rustompm...@gmail.com> wrote: > Can someone explain what is happening here? > *Main> getTwoChars > ab > ('a','b') > *Main> getTwoChars > a > ('\n','a') > The code is doing exactly what it says. getTwoChars reads two characters --- *not* a line. So the next character waiting to be read is the newline, which is returned by the next getTwoChars. This may depend to some extent on the platform, as Unix defaults to a line-oriented input interface (at the OS level) but Windows to character-oriented input. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111027/62c64b43/attachment-0001.htm> ------------------------------ Message: 8 Date: Thu, 27 Oct 2011 14:49:07 -0500 From: Noah Diewald <n...@diewald.me> Subject: Re: [Haskell-beginners] Need some advices about university To: beginners@haskell.org Message-ID: <4ea9b5b3.4020...@diewald.me> Content-Type: text/plain; charset="utf-8" It would be nice to know of a school somewhere in the US or Canada where CS courses aren't taught mostly in Java. Is there such a place? I would love to find a school with strengths in FP and linguistics. Feeling as though this will be impossible keeps me more focused on applying to theoretical linguistics departments and figuring that I'll just have to use text books and the Internet for the computational component, which will probably mean I'll get ok in linguistics but not as good as I would like to be with FP. Human interactions, outside expectations and having some type of mentor are so important. Learning more Java seems like such a waste of mental energy and time. I mean a theoretical linguist steeped in minimalism would never just hand over their future education to connectionists. Even if they discover new things about language, they won't be focusing on the ideas that they really wanted to build their strength in. Why is Java considered such a great educational language anyway? It seems great for making cubicle warmers but the future employment of students seems like it should be the least concern for people who's focus is ideas and discovery. I guess this sounds a little frustrated? Does anyone have any suggestions? Kansas University in Lawrence looks to have a lot of Haskell activity (maybe not in courses) and a good looking linguistics department. This might be helpful to Zhi-Qiang Lei: http://www.ittc.ku.edu/csdl/fpg/Home On 10/26/2011 09:04 AM, Brent Yorgey wrote: > On Wed, Oct 26, 2011 at 01:56:05PM +0800, Zhi-Qiang Lei wrote: >> Hi, >> >> I'm making a plan to gain more computer knowledge (functional >> programming and Haskell especially) and a Master's degree in a >> university. Does anybody know which university in USA has good >> resources in this domain? Thanks. > > The University of Pennsylvania has a good masters' degree program and > a great programming languages group -- although they are not really > connected (you would not get to study a whole lot of FP stuff while > doing the masters' degree). But of course you could come to the PL > group meetings. > > -Brent > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: <http://www.haskell.org/pipermail/beginners/attachments/20111027/297a4df1/attachment.pgp> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 40, Issue 43 *****************************************