Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Review request (C K Kashyap)
2. Re: Review request (Carlos J. G. Duarte)
----------------------------------------------------------------------
Message: 1
Date: Mon, 16 Jul 2012 16:40:45 +0530
From: C K Kashyap <[email protected]>
Subject: Re: [Haskell-beginners] Review request
To: "Carlos J. G. Duarte" <[email protected]>
Cc: [email protected]
Message-ID:
<cagdt1govmw+mimmmq-xcejzdwcx1uzrf+w11pdmuembafsa...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thanks Carlos - you can import Text.Regex.Posix to get (=~)
Is there a way to avoid the (++) in your implementation? It has a linear
time overhead.
Regards,
Kashyap
On Mon, Jul 16, 2012 at 1:36 AM, Carlos J. G. Duarte <
[email protected]> wrote:
> Looks good to me, but I'm just a beginner!
> I used the isInfixOf from Data.List instead of =~ to run your example
> because the later wasn't working on my instalation.
>
> I've made a slightly variant using the break function:
>
> import Data.List
>
> startTag = "<bug>"
> endTag = "</bug>"
>
> main = interact process
>
> process = unlines . extractSection startTag endTag . lines
> extractSection start stop xs =
> let (ls,rs) = break (isInfixOf stop) $ dropWhile (not . isInfixOf start)
> xs
> in ls ++ take 1 rs
>
>
>
> On 07/15/12 13:08, C K Kashyap wrote:
>
> Hi,
> I've written a small haskell program to extract a section from a file
> between start and end markers. For example, if I have a file such as below
> -
> a
> b
> c
> <bug>
> d
> e
> f
> </bug>
> g
> h
> i
>
> I'd like to extract the contents between <bug> and </bug> (including the
> markers).
>
> startTag = "<bug>"endTag = "</bug>"
> process = unlines . specialTakeWhile (f endTag) . dropWhile (f startTag) .
> lines
> where f t x = not (x =~ t)
> specialTakeWhile :: (a -> Bool) -> [a] -> [a]
> specialTakeWhile ff [] = []
> specialTakeWhile ff (x:xs) = if ff x then x:(specialTakeWhile
> ff xs)** else [x]
>
> It'll be great if I could get some feedback on this.
>
> Regards,
>
> Kashyap
>
>
>
> _______________________________________________
> Beginners mailing
> [email protected]http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120716/491783ee/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 16 Jul 2012 17:57:59 +0100
From: "Carlos J. G. Duarte" <[email protected]>
Subject: Re: [Haskell-beginners] Review request
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120716/7a39c0a5/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 49, Issue 18
*****************************************