Re: [Haskell-cafe] how to calculate the sum of list of lists?

2007-02-05 Thread Eric Olander

If I understand you correctly, this should do it:

sums :: Num a = [[a]] - a
sums l = sum [sum p | p - l]

-Eric

On 2/5/07, Miranda Kajtazi [EMAIL PROTECTED] wrote:


Help,

How to calculate the sum of list of lists in Haskell?
Please help me,
Miranda

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] List operation question

2007-02-05 Thread Eric Olander

That's a clever routine.  It should be faster than mine since it only makes
a single pass though the list.  Thanks for all the suggestions from everyone
that responded.  Here is a link to some more info on the project I'm working
on if anyone is interested:  http://ehaskell.blogspot.com/

-Eric

On 2/5/07, ihope [EMAIL PROTECTED] wrote:


On 2/4/07, Eric Olander [EMAIL PROTECTED] wrote:
 Hi,
I'm still somewhat new to Haskell, so I'm wondering if there are
better
 ways I could implement the following functions, especially shiftl:

  moves the last element to the head of the list
 shiftl :: [a] - [a]
 shiftl [] = []
 shiftl x = [last x] ++ init x

Well, you could try this, though I'm actually sure it's any faster:

 shiftl (x1:x2:xs) = last:x1:init
   where last:init = shiftl (x2:xs)
 shiftl [x] = [x]
 shiftl [] = error shiftl: empty list

Or, if you don't want to give an error on [], omit the last line and
replace both of the [x] with xs.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] List operation question

2007-02-04 Thread Eric Olander

Hi,
  I'm still somewhat new to Haskell, so I'm wondering if there are better
ways I could implement the following functions, especially shiftl:


moves the first element to the end of the list

   shiftr :: [a] - [a]
   shiftr [] = []
   shiftr (x:y) = y ++ [x]


moves the last element to the head of the list

   shiftl :: [a] - [a]
   shiftl [] = []
   shiftl x = [last x] ++ init x

-Eric
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe