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.  a simple problem (Anonymous W)
   2.  Can ghc compiler Optimize the several calls to   Same function
      (nicholas.ulysses)
   3.  ANNOUNCE: Haskell Communities and Activities Report (19th
      ed., November 2010) (Janis Voigtl?nder)
   4. Re:  Can ghc compiler Optimize the several calls  to Same
      function (edgar klerks)
   5. Re:  Can ghc compiler Optimize the several calls  to Same
      function (Daniel Fischer)
   6.  Why the length function I wrote has such a type  signature? (???)
   7. Re:  Why the length function I wrote has such a   type
      signature? (Chadda? Fouch?)


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

Message: 1
Date: Wed, 3 Nov 2010 15:31:09 -0700 (PDT)
From: Anonymous W <[email protected]>
Subject: [Haskell-beginners] a simple problem
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,
I'm having trouble with this small exercise. 
 
A function maybeA takes a list of pairs. A pair has a variable 'a' and a value 
'b'. If any first element of a pair equals to any first element of another 
pair, 
the function returns Nothing. If they aren't equal, the function returns a 
tuple 
containing the first variable, its value and the value of the second variable.
maybeA :: [(a,b)] -> Maybe (a,b,b)


For example:  [(a1,b1),(a2,b2),(a3,b3)..] returns Nothing if a2 = a3 
and returns 
Just (a2,b2,b3) if  a2 /= a3
 
I'm currently have :maybeA [(a1,b1),(a2,b2)] 
    |a1 == a2 = Nothing
    |a1 /= a2 = Just (x1,y1,y2)
but it only takes 2 pairs. Any helps?
 
Thanks


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20101103/3b6161ca/attachment-0001.html

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

Message: 2
Date: Mon, 8 Nov 2010 21:08:28 +0800
From: "nicholas.ulysses" <[email protected]>
Subject: [Haskell-beginners] Can ghc compiler Optimize the several
        calls to        Same function
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

It's my code to do some recursive things, focus on function 'group'.

---- cow.hs
  year1 [y1,y2,y3,y4x] = y1
  year2 [y1,y2,y3,y4x] = y2
  year3 [y1,y2,y3,y4x] = y3
  year4x [y1,y2,y3,y4x] = y4x
  cow_group_sum year = sum (group year)

  --look here--
  group 1 = [1,0,0,0]
  group (year+1) = [(year4x (group year)), (year1 (group year)),
(year2 (group year)), ((year4x (group year)) + (year3 (group year)))]


  main = print (cow_group_sum 50)
---- end

Every time 'group' was called, the (group year) function was called 4
times . when call (group 30), it takes tens seconds to finish.

I have tried 'ghc -O3', but it's still 'lazy' on this thing.

Map-Reduce seems to be the answer to the question. But I want to make
sure that ghc CAN or CANNOT do the Optimize for Dynamic Programming?


----------------
xingbo wu


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

Message: 3
Date: Tue, 09 Nov 2010 10:28:28 +0100
From: Janis Voigtl?nder <[email protected]>
Subject: [Haskell-beginners] ANNOUNCE: Haskell Communities and
        Activities Report (19th ed., November 2010)
To: Haskell <[email protected]>, [email protected],
        [email protected], [email protected],
        [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed

On behalf of all the contributors, I am pleased to announce that the

            Haskell Communities and Activities Report
                  (19th edition, November 2010)

is now available in PDF and HTML formats:

   http://haskell.org/communities/11-2010/report.pdf
   http://haskell.org/communities/11-2010/html/report.html

Many thanks go to all the people that contributed to this report,
both directly, by sending in descriptions, and indirectly, by doing
all the interesting things that are reported. I hope you will find
it as interesting a read as I did.

If you have not encountered the Haskell Communities and Activities
Reports before, you may like to know that the first of these reports
was published in November 2001. Their goal is to improve the
communication between the increasingly diverse groups, projects, and
individuals working on, with, or inspired by Haskell. The idea behind
these reports is simple:

   Every six months, a call goes out to all of you enjoying Haskell to
   contribute brief summaries of your own area of work. Many of you
   respond (eagerly, unprompted, and sometimes in time for the actual
   deadline ;-) to the call. The editor collects all the contributions
   into a single report and feeds that back to the community.

When I try for the next update, six months from now, you might want
to report on your own work, project, research area or group as well.
So, please put the following into your diaries now:

            ----------------------------------------
                      End of April 2011:
            target deadline for contributions to the
              May 2011 edition of the HC&A Report
            ----------------------------------------

Unfortunately, many Haskellers working on interesting projects are so
busy with their work that they seem to have lost the time to follow
the Haskell related mailing lists and newsgroups, and have trouble even
finding time to report on their work. If you are a member, user or
friend of a project so burdened, please find someone willing to make
time to report and ask them to "register" with the editor for a simple
e-mail reminder in April (you could point me to them as well, and I
can then politely ask if they want to contribute, but it might work
better if you do the initial asking). Of course, they will still have to
find the ten to fifteen minutes to draw up their report, but maybe we
can increase our coverage of all that is going on in the community.

Feel free to circulate this announcement further in order to
reach people who might otherwise not see it. Enjoy!

Janis Voigtlaender
<hcar at haskell.org>


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

Message: 4
Date: Thu, 11 Nov 2010 01:40:18 +0100
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] Can ghc compiler Optimize the several
        calls   to Same function
To: "nicholas.ulysses" <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi Nicholas,

If you use a where statement, GHC only has to compute the computation group
year once, because it can be shared.

year1 [y1,y2,y3,y4x] = y1
year2 [y1,y2,y3,y4x] = y2
year3 [y1,y2,y3,y4x] = y3
year4x [y1,y2,y3,y4x] = y4x
cow_group_sum year = sum (group year)

      --look here--
group 1 = [1,0,0,0]
group (year+1) = [year4x gy, year1 gy,year2 gy,year4x gy + year3 gy]
        where gy = group year

main = print (cow_group_sum 50)

This works a lot faster.

I don't understand why GHC doesn't pick this up.

Greets,

Edgar
On Mon, Nov 8, 2010 at 2:08 PM, nicholas.ulysses <[email protected]
> wrote:

> It's my code to do some recursive things, focus on function 'group'.
>
> ---- cow.hs
>  year1 [y1,y2,y3,y4x] = y1
>  year2 [y1,y2,y3,y4x] = y2
>  year3 [y1,y2,y3,y4x] = y3
>  year4x [y1,y2,y3,y4x] = y4x
>  cow_group_sum year = sum (group year)
>
>  --look here--
>  group 1 = [1,0,0,0]
>  group (year+1) = [(year4x (group year)), (year1 (group year)),
> (year2 (group year)), ((year4x (group year)) + (year3 (group year)))]
>
>
>  main = print (cow_group_sum 50)
> ---- end
>
> Every time 'group' was called, the (group year) function was called 4
> times . when call (group 30), it takes tens seconds to finish.
>
> I have tried 'ghc -O3', but it's still 'lazy' on this thing.
>
> Map-Reduce seems to be the answer to the question. But I want to make
> sure that ghc CAN or CANNOT do the Optimize for Dynamic Programming?
>
>
> ----------------
> xingbo wu
> _______________________________________________
> 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/20101110/64e5b1fa/attachment-0001.html

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

Message: 5
Date: Thu, 11 Nov 2010 02:09:20 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Can ghc compiler Optimize the several
        calls   to Same function
To: [email protected]
Cc: "nicholas.ulysses" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Thursday 11 November 2010 01:40:18, edgar klerks wrote:
> Hi Nicholas,
>
> If you use a where statement,

Or a let binding, whatever one prefers.

> GHC only has to compute the computation
> group year once, because it can be shared.
>
> year1 [y1,y2,y3,y4x] = y1
> year2 [y1,y2,y3,y4x] = y2
> year3 [y1,y2,y3,y4x] = y3
> year4x [y1,y2,y3,y4x] = y4x
> cow_group_sum year = sum (group year)
>
>       --look here--
> group 1 = [1,0,0,0]
> group (year+1) = [year4x gy, year1 gy,year2 gy,year4x gy + year3 gy]
>         where gy = group year
>
> main = print (cow_group_sum 50)
>
> This works a lot faster.

That, or

group (year+1) =
  case group year of
    [y1,y2,y3,y4x] -> [y4x,y1,y2,y4x+y3]
    _ -> error "oops"


Note, however, that (n+k)-patterns have been removed in Haskell2010, so the 
code won't compile with the next GHC unless you turn on the NPlusKPatterns 
extension.

>
> I don't understand why GHC doesn't pick this up.

GHC does very little common subexpression elimination (CSE).
The reason is that CSE can have disastrous effects, as sharing can lead to 
huge memory requirements (imagine sharing a loong list for example).
Unconditionally doing CSE is hence not an option, and finding out when 
sharing will be beneficial and when it will be detrimental is very hard 
(possibly impossible in general).
So it's basically left to the programmer to decide when to share.
Give it a name and it will be shared, otherwise probably not.

>
> Greets,
>
> Edgar
> On Mon, Nov 8, 2010 at 2:08 PM, nicholas.ulysses
> <[email protected]
>
> > wrote:
> >
> > It's my code to do some recursive things, focus on function 'group'.
> >
> > ---- cow.hs
> >  year1 [y1,y2,y3,y4x] = y1
> >  year2 [y1,y2,y3,y4x] = y2
> >  year3 [y1,y2,y3,y4x] = y3
> >  year4x [y1,y2,y3,y4x] = y4x
> >  cow_group_sum year = sum (group year)
> >
> >  --look here--
> >  group 1 = [1,0,0,0]
> >  group (year+1) = [(year4x (group year)), (year1 (group year)),
> > (year2 (group year)), ((year4x (group year)) + (year3 (group year)))]
> >
> >
> >  main = print (cow_group_sum 50)
> > ---- end
> >
> > Every time 'group' was called, the (group year) function was called 4
> > times . when call (group 30), it takes tens seconds to finish.
> >
> > I have tried 'ghc -O3', but it's still 'lazy' on this thing.
> >
> > Map-Reduce seems to be the answer to the question. But I want to make
> > sure that ghc CAN or CANNOT do the Optimize for Dynamic Programming?
> >
> >
> > ----------------
> > xingbo wu



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

Message: 6
Date: Thu, 11 Nov 2010 16:24:44 +0800
From: ??? <[email protected]>
Subject: [Haskell-beginners] Why the length function I wrote has such
        a type  signature?
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

This is exercise 3.1 of Real World Haskell. I have my length function like
this:

myLength [] = 0
myLength (_:xs) = 1 + (myLength xs)

And I assumed the type signature is like this:
mylength :: [a] -> Num

But when I wrote this into the file and reloaded it into ghci, there is an
error.

>     The type signature for `mylength' lacks an accompanying binding
> Failed, modules loaded: none.
>

And the type signature given by ghci is

> myLength :: (Num t1) => [t] -> t1
>

So how can I modify the function to have a type signature like the first
one?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20101111/b3aeb15e/attachment-0001.html

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

Message: 7
Date: Thu, 11 Nov 2010 09:34:11 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Why the length function I wrote has
        such a  type signature?
To: ??? <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Thu, Nov 11, 2010 at 9:24 AM, 贾旭卿 <[email protected]> wrote:
> This is exercise 3.1 of Real World Haskell. I have my length function like
> this:
>
> myLength [] = 0
> myLength (_:xs) = 1 + (myLength xs)
>
> And I assumed the type signature is like this:
> mylength :: [a] -> Num
>
> But when I wrote this into the file and reloaded it into ghci, there is an
> error.
>>
>>     The type signature for `mylength' lacks an accompanying binding
>> Failed, modules loaded: none.
>
>
> And the type signature given by ghci is
>>
>> myLength :: (Num t1) => [t] -> t1
>
> So how can I modify the function to have a type signature like the first
> one?

You can't, since Num isn't a type, it's a typeclass.

> myLength :: (Num b) => [a] -> b

means that myLength takes a list of any type and can return any type
that is an instance of Num (Num being the typeclass of numbers, that
means that you can do most things you do on numbers, adding them,
multiplying them, and so on...).

If you want a simpler type signature, you could use :

> myLength :: [a] -> Int

or

> myLength :: [a] -> Integer

since Int (32 or 64 bits integer) and Integer are real type that are
instances of the Num typeclass.

-- 
Jedaï


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

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


End of Beginners Digest, Vol 29, Issue 15
*****************************************

Reply via email to