Project Euler Problem 50 in Haskell
Here is my approach:

First some imports:

 {-# LANGUAGE BangPatterns #-}

 module Euler50
 where

 import Math.NumberTheory.Primes
 import qualified Data.IntSet as Set
 import Data.List
 import Debug.Trace


We use the arithmoi library to get the primes:

 myPrimes :: [Int]
 myPrimes = map fromIntegral $ takeWhile (&lt; 1000000) primes

 myPrimeSet :: Set.IntSet
 myPrimeSet = Set.fromList myPrimes

 myIsPrime :: Int -&gt; Bool
 myIsPrime p = Set.member p myPrimeSet


To solve the problem, let's first define a function to produce consecutive sums of a list:

 consecutiveSums0 :: [Int] -&gt; [(Int,Int)]
 consecutiveSums0 ps = scanl step (0,0) ps
   where step (!n,!total) p = (n+1, total+p)


For example, consecutiveSums0 [2,3,5,7] will produce the list:

[ (0,0), (1,2), (2,5), (3,10), (4,17) ]


It will be useful to be able to specify a starting value for the
accumulator, so we'll define:

 consecutiveSums :: (Int,Int) -&gt; [Int] -&gt; [(Int,Int)]
 consecutiveSums start ps = scanl step start ps
   where step (!n,!total) p = (n+1, total+p)


Next, we filter out only the prime sums
which are less than 1000000:

 primeSums :: (Int,Int) -&gt; [Int] -&gt; [ (Int,Int) ]
 primeSums start ps = filter (myIsPrime . snd ) $ takeWhile ( (&lt;1000000) . snd ) $ consecutiveSums start ps


A naive solution to the problem involves repeatedly calling primeSums on the tails of
our list of primes:

 solve0 = maximum $ concat $ map (primeSums (0,0)) (tails myPrimes)


However, there are 78498 primes less than 1000000 and this will examine
approximate 78498^2/2 sums which will take too long.

A better solution involves keeping track of the best solution found so far
and using that to enforce the minimal size of any better solution.
We can stop once the minimal size constraint forces the total of any better
solution to be greater than 1000000.

Our loop will have this structure:

 loop :: [Int]        -- current list of primes
      -&gt; (Int,Int)    -- best solution so far (n, total)
      -&gt; (Int,Int)    -- best solution


The idea is that loop ps b1 will compute a new best solution b2
and then call loop (tail ps) b2 which will compute a new best b3
and call loop (tail (tail ps)) b3 etc. The iteration will stop
when either the primes list is exhausted or the above stopping condition
holds.

An easy case:

 loop [] best = best  -- prime list has been exhausted


We include this just to trace the execution of the function
- it has no effect on the computation:

 loop (p:_) best | trace msg False = undefined
   where msg = "--- p = " ++ show p ++ "  best: " ++ show best


The main definition is:

 loop ps best@(n,total) = 
   let (as, bs) = splitAt (n+1) ps -- better solution must have at least n+1 primes
       total0 = sum as
   in
   if total0 &gt;= 1000000
      then best
      else let best' = maximum $ [best] ++ primeSums (n+1, total0) bs
           in
           loop (tail ps) best'


To kick everything off:

 solution = loop myPrimes (0,0)


which results in the followin output:

*Euler50&gt; solution
--- p = 2  best: (0,0)
--- p = 3  best: (536,958577)
--- p = 5  best: (536,958577)
--- p = 7  best: (539,978037)
--- p = 11  best: (543,997651)
(543,997651)


So the longest sum begins at 7 and has length 543 and has sum 997651.
Solving the problem only involves looking at sums which start from the first
five primes.