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:  Comments on Map/Reduce Code (Thomas Bach)
   2. Re:  Comments on Map/Reduce Code (Brent Yorgey)
   3. Re:  Review request (C K Kashyap)


----------------------------------------------------------------------

Message: 1
Date: Tue, 17 Jul 2012 15:01:39 +0200
From: Thomas Bach <[email protected]>
Subject: Re: [Haskell-beginners] Comments on Map/Reduce Code
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On Sat, Jul 14, 2012 at 08:35:44PM -0400, Brent Yorgey wrote:
> On Fri, Jul 13, 2012 at 06:02:02PM +0200, Thomas Bach wrote:
> 
> > The reducer still throws an error when piping in an empty
> > newline. But, I'm not sure, what a proper solution for this could be.
> 
> The problem is your 'summation' function:
> 
>   summation :: Num b => [(a, b)] -> (a, b)
> 
> In fact, it is impossible to implement something with this type which
> works for all inputs.  If you get the empty list as input, there is no
> way to make up a value of type 'a' in the output tuple.
> 

It really is not that big of a deal. As I'd assume that Hadoop
guarantees that at least one line will be passed to the reducer. But,
just out of curiosity: wouldn't this be a case where monads are
applied? Say, `Maybe'? So that the type becomes

summation :: Num b => [(a, b)] -> Maybe (a, b)

Or is the semantic behind monads a different one?


Regards,
        Thomas



------------------------------

Message: 2
Date: Tue, 17 Jul 2012 09:28:02 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Comments on Map/Reduce Code
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, Jul 17, 2012 at 03:01:39PM +0200, Thomas Bach wrote:
> On Sat, Jul 14, 2012 at 08:35:44PM -0400, Brent Yorgey wrote:
> > On Fri, Jul 13, 2012 at 06:02:02PM +0200, Thomas Bach wrote:
> > 
> > > The reducer still throws an error when piping in an empty
> > > newline. But, I'm not sure, what a proper solution for this could be.
> > 
> > The problem is your 'summation' function:
> > 
> >   summation :: Num b => [(a, b)] -> (a, b)
> > 
> > In fact, it is impossible to implement something with this type which
> > works for all inputs.  If you get the empty list as input, there is no
> > way to make up a value of type 'a' in the output tuple.
> > 
> 
> It really is not that big of a deal. As I'd assume that Hadoop
> guarantees that at least one line will be passed to the reducer. But,
> just out of curiosity: wouldn't this be a case where monads are
> applied? Say, `Maybe'? So that the type becomes
> 
> summation :: Num b => [(a, b)] -> Maybe (a, b)

Yes, wrapping the return type in Maybe could be a good idea indeed.
You say "wouldn't this be a case where monads are applied", but you
are jumping too far ahead: using Maybe in this way is a good idea no
matter whether you happen to know that Maybe is an instance of Monad
or not.  Likewise, you could work with a function of this type without
using the Monad interface at all.  Using the Monad interface might
simplify some of the code but it is by no means required.

-Brent



------------------------------

Message: 3
Date: Tue, 17 Jul 2012 19:52:52 +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:
        <cagdt1grf_med3bag_bkxeaysyjoaybz9svrz025_c5qcafy...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I did some more refining and I like this one much better -

import Text.Regex.Posix


start = "<bug>"
end = "</bug>"


{-
s = start encountered
e = end encountered
ns = new start encountered
ne = new encountered
-}
process s e []     = []
process s e (x:xs) = if ns && not ne then
                        x : process ns ne xs
                     else
                        if ne then
                           [x]
                        else
                           process ns ne xs
        where ns = if s then
                      s
                   else
                      x =~ start
              ne = x =~ end


main = do
     str <- readFile "test.txt"
     let x = process False False (lines str)
     print (unlines x)



On Mon, Jul 16, 2012 at 10:27 PM, Carlos J. G. Duarte <
[email protected]> wrote:

>  I see what you mean. I wasn't aware of the slowness of ++
> So your solution is just fine (? asking): you've just made a special
> takewhile that includes the matching predicate and handled the input like a
> pipeline.
> It reminds a Unix command line, in the case: awk '/<bug>/,NR==0'  | awk
> 'NR==1,/<\/bug>/'
>
>
>
> On 07/16/12 12:10, C K Kashyap wrote:
>
> 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
>>
>>
>
>
>
> _______________________________________________
> 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/20120717/913c2ac3/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 49, Issue 19
*****************************************

Reply via email to