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. Re: mayBe stuck (prad) 2. Re: Re: mayBe stuck (J?rgen Doser) 3. Re: mayBe stuck (prad) 4. Re: mayBe stuck (prad) 5. Re: Re: Boilerplate Code (Matt Andrew) 6. Re: mayBe stuck (Brent Yorgey) 7. Re: Parsec (Dean Herington) 8. Re: mayBe stuck (Dean Herington) 9. Re: mayBe stuck (Colin Paul Adams) 10. Re: Parsec (C Gosch) ---------------------------------------------------------------------- Message: 1 Date: Thu, 5 Aug 2010 17:08:51 -0700 From: prad <p...@towardsfreedom.com> Subject: [Haskell-beginners] Re: mayBe stuck To: beginners@haskell.org Message-ID: <20100805170851.4c7e3...@gom> Content-Type: text/plain; charset=ISO-8859-1 On Fri, 06 Aug 2010 00:52:51 +0200 Jürgen Doser <jurgen.do...@gmail.com> wrote: > But really, you are doing it the wrong way. Your code is traversing > the list once to find sth. (the findIndex ...), and then traversing > it again to split it (the take i ...). Why not split directly when > you find what you are looking for? > ya i will think about this now that the other issue has been explained! the way i was doing it seemed a bit funny (and i initially tried findIndices), but couldn't see how to use the limited tools i'm aware of. i was wanting to do something like keep pulling characters and make a new string until the delimiter was found fn cs = [x | x <- cs, x /= '%'] : [] but can't figure out how to use this idea to actually cause splitting into [String] i also explored break and splitAt, but haven't quite worked out a mechanism to use those, yet. thx again for your help. -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's ------------------------------ Message: 2 Date: Fri, 06 Aug 2010 02:44:26 +0200 From: J?rgen Doser <jurgen.do...@gmail.com> Subject: Re: [Haskell-beginners] Re: mayBe stuck To: beginners@haskell.org Message-ID: <1281055466.3497.22.ca...@imedia.irun.org> Content-Type: text/plain; charset=utf-8 El jue, 05-08-2010 a las 17:08 -0700, prad escribió: > > i was wanting to do something like keep pulling characters and make a > new string until the delimiter was found "keep pulling ... until the delimiter was found" sounds suspiciously like takeWhile and friends (like break, see below). > fn cs = [x | x <- cs, x /= '%'] : [] This doesn't split, it just filters. In particular, you have no way of knowing where in the string elements where discarded. > but can't figure out how to use this idea to actually cause splitting > into [String] Neither do I :) > i also explored break and splitAt, but haven't quite worked out a > mechanism to use those, yet. break is exactly what I would use. The only problem is that break will only look for the first delimiter match. To get all the matches, you will have to get the recursion right... For practice purposes, in particular for getting used to recursion, it might also be useful to write the function without any help of library functions, traversing the string using direct recursion only. For every character you encounter, what do you have to do in each case? Jürgen ------------------------------ Message: 3 Date: Thu, 5 Aug 2010 19:07:13 -0700 From: prad <p...@towardsfreedom.com> Subject: [Haskell-beginners] Re: mayBe stuck To: beginners@haskell.org Message-ID: <20100805190713.15992...@gom> Content-Type: text/plain; charset=ISO-8859-1 On Fri, 06 Aug 2010 02:44:26 +0200 Jürgen Doser <jurgen.do...@gmail.com> wrote: > For practice purposes, in particular for getting used to recursion, it > might also be useful to write the function without any help of library > functions, traversing the string using direct recursion only. For > every character you encounter, what do you have to do in each case? > you are a good teacher, jurgen! here's what i came up with: br [] = [] br ss = fst (tup) : br (tail (snd tup)) where tup = break eqD ss now this works great for let s = "zaoeu%aeuasnt%staashaeu%nthdanoe%nthd%" but i get a *** Exception: Prelude.tail: empty list i found a neat way to explore recursion on ghci like this Prelude> let s = "aoeu%snthi%ashuet" Prelude> break (=='%') s ("aoeu","%snthi%ashuet") Prelude> break (=='%') (tail (snd it)) ("snthi","%ashuet") Prelude> break (=='%') (tail (snd it)) ("ashuet","") Prelude> break (=='%') (tail (snd it)) *** Exception: Prelude.tail: empty list of course this is the problem i'm having in that i'm forced to take the tail of an empty list at the end. correcting it by sticking on a delimiter doesn't seem to be the right thing to do though. so there must be another way to deal with this. hmmm. -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's ------------------------------ Message: 4 Date: Thu, 5 Aug 2010 20:34:57 -0700 From: prad <p...@towardsfreedom.com> Subject: [Haskell-beginners] Re: mayBe stuck To: beginners@haskell.org Message-ID: <20100805203457.639a9...@gom> Content-Type: text/plain; charset=US-ASCII On Thu, 5 Aug 2010 19:07:13 -0700 prad <p...@towardsfreedom.com> wrote: > correcting it by sticking on a > delimiter doesn't seem to be the right thing to do though. so there > must be another way to deal with this. hmmm. > i think i can solve the dilemma by introducing an accessory function getTail: br [] = [] br ss = fst (tup) : br (getTail (snd tup)) where tup = break eqD ss getTail s | s==[] = [] | otherwise = tail s it works, though i don't know if this is necessarily the best way to do it. -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's ------------------------------ Message: 5 Date: Fri, 06 Aug 2010 13:56:30 +1000 From: Matt Andrew <mjsa...@gmail.com> Subject: Re: [Haskell-beginners] Re: Boilerplate Code To: beginners <beginners@haskell.org> Message-ID: <87bp9gfl75.wl%mjsa...@gmail.com> Content-Type: text/plain; charset=US-ASCII Hi Claus, Thanks for the food for thought, Common Lisp is the language I'd spent the most time with before Haskell so meta-programming is where I tend to head when dealing with this kind of abstraction; it's nice to see how else the problem can be tackled. Also apologies that my replies seem to be starting new threads. I hope that's fixed with this message. Cheers, Matt ------------------------------ Message: 6 Date: Fri, 6 Aug 2010 07:57:17 +0100 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] mayBe stuck To: aditya siram <aditya.si...@gmail.com> Cc: beginners@haskell.org Message-ID: <20100806065717.ga23...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Thu, Aug 05, 2010 at 06:20:06PM -0500, aditya siram wrote: > Normally yes, but here we are guaranteed to get a 'Just ...' value because > of the 'isNothing' guard. > -deech You are correct, but that's not the point. Every time you use fromJust (or head, or unsafePerformIO...) you shift the burden of proving that it is safe from the compiler onto yourself. It's like going to a fancy restaurant and insisting on going into the kitchen and cooking your own meal. -Brent > > On Thu, Aug 5, 2010 at 5:47 PM, Brent Yorgey <byor...@seas.upenn.edu> wrote: > > > On Thu, Aug 05, 2010 at 05:42:40PM -0500, aditya siram wrote: > > > > > > brS :: Maybe Int -> String -> String > > > brS i ss > > > | isNothing i = ss > > > | otherwise = (take (fromJust i) ss) ++ (brS newIndex newStr) > > > where > > > newIndex = findIndex eqD newStr > > > newStr = drop ((fromJust i) +1) ss > > > > /me makes deech write on the blackboard 100 times, "I will not use > > fromJust" > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > ------------------------------ Message: 7 Date: Fri, 6 Aug 2010 03:24:37 -0400 From: Dean Herington <heringtonla...@mindspring.com> Subject: Re: [Haskell-beginners] Parsec To: C Gosch <ch.go...@googlemail.com>, beginners@haskell.org Message-ID: <a06240801c881688c0...@[10.0.1.4]> Content-Type: text/plain; charset="us-ascii" ; format="flowed" At 11:42 PM +0200 8/5/10, C Gosch wrote: >Hi, >does anyone here know their way around in Parsec? >I'm trying to parse a file which contains some binary parts too. >I have been using Parsec 3.0.1 to parse the first ASCII part, but >all the parsers are >returning Char type tokens, so it would not work with the binary parts .. >is there any way to do this? >I am using Text.Parsec.ByteString.Lazy. > >Note that I'm new to Haskell and Parsec, and doing this within a >small project that >I basically do to get a grip on Haskell (and Parsec, because it >appears to be really nifty and I want to learn more about it). > >Thanks for any hints, >Christian Parsing binary parts of a file is not inherently a problem. A parser can return any type; different parsers in your application will likely return different types. If you include some code we'll be able to help you more specifically. Dean ------------------------------ Message: 8 Date: Fri, 6 Aug 2010 03:43:30 -0400 From: Dean Herington <heringtonla...@mindspring.com> Subject: [Haskell-beginners] Re: mayBe stuck To: prad <p...@towardsfreedom.com>, beginners@haskell.org Message-ID: <a06240802c8816aab8...@[10.0.1.4]> Content-Type: text/plain; charset="us-ascii" ; format="flowed" At 8:34 PM -0700 8/5/10, prad wrote: >On Thu, 5 Aug 2010 19:07:13 -0700 >prad <p...@towardsfreedom.com> wrote: > >> correcting it by sticking on a >> delimiter doesn't seem to be the right thing to do though. so there >> must be another way to deal with this. hmmm. >> >i think i can solve the dilemma by introducing an accessory function >getTail: > >br [] = [] >br ss = fst (tup) : br (getTail (snd tup)) > where > tup = break eqD ss > getTail s > | s==[] = [] > | otherwise = tail s > >it works, though i don't know if this is necessarily the best way to do >it. > >-- >In friendship, >prad I would write something like: br [] = [] br ss = let (h, t) = break eqD ss in h : case t of [] -> [] _ : t -> br t Dean ------------------------------ Message: 9 Date: Fri, 06 Aug 2010 09:40:05 +0100 From: Colin Paul Adams <co...@colina.demon.co.uk> Subject: Re: [Haskell-beginners] mayBe stuck To: Brent Yorgey <byor...@seas.upenn.edu> Cc: beginners@haskell.org Message-ID: <m3mxt0dti2....@colina.demon.co.uk> Content-Type: text/plain; charset=us-ascii >>>>> "Brent" == Brent Yorgey <byor...@seas.upenn.edu> writes: Brent> On Thu, Aug 05, 2010 at 06:20:06PM -0500, aditya siram wrote: >> Normally yes, but here we are guaranteed to get a 'Just ...' >> value because of the 'isNothing' guard. -deech Brent> You are correct, but that's not the point. Every time you Brent> use fromJust (or head, or unsafePerformIO...) you shift the Brent> burden of proving that it is safe from the compiler onto Brent> yourself. But the compiler could indeed prove that it's safe, if the typing system reflected the precondition. Since Haskell allows programming with partial functions, you always have this burden at present. -- Colin Adams Preston Lancashire () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments ------------------------------ Message: 10 Date: Fri, 6 Aug 2010 11:03:50 +0200 From: C Gosch <ch.go...@googlemail.com> Subject: Re: [Haskell-beginners] Parsec To: Dean Herington <heringtonla...@mindspring.com> Cc: beginners@haskell.org Message-ID: <aanlkti=oudhqyherkoxqd82vnpkz7_yufzs3fxjmh...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" 2010/8/6 Dean Herington <heringtonla...@mindspring.com> > At 11:42 PM +0200 8/5/10, C Gosch wrote: > >> Hi, >> does anyone here know their way around in Parsec? >> I'm trying to parse a file which contains some binary parts too. >> I have been using Parsec 3.0.1 to parse the first ASCII part, but all the >> parsers are >> returning Char type tokens, so it would not work with the binary parts .. >> is there any way to do this? >> I am using Text.Parsec.ByteString.Lazy. >> >> Note that I'm new to Haskell and Parsec, and doing this within a small >> project that >> I basically do to get a grip on Haskell (and Parsec, because it appears to >> be really nifty and I want to learn more about it). >> >> Thanks for any hints, >> Christian >> > > Parsing binary parts of a file is not inherently a problem. A parser can > return any type; different parsers in your application will likely return > different types. > > If you include some code we'll be able to help you more specifically. > > Dean > You're right, I probably used the wrong words .. I meant that apparently the tokens Parsec uses are of type Char, and I would actually at some point like to continue parsing, but using different tokens. Sorry if I still got it wrong, I'm new :) I can post some code later, as I don't have it here right now. Cheers, Christian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20100806/0675e20e/attachment.html ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 26, Issue 13 *****************************************