[Haskell-beginners] Monadic Project Euler 1

Javier M Mora jamarier at gmail.com
Thu Feb 17 22:02:58 CET 2011


On 17/02/11 20:54, Ozgur Akgun wrote:
> On 17 February 2011 19:13, Javier M Mora <jamarier at gmail.com
> <mailto:jamarier at gmail.com>> wrote:
>
>     First Step: What I want?
>     ------------------------
>
>     In this problem: I think monads as a DSL (Domain Specific Language)
>
>     main = do
>       print $ sumM $ do
>         makeList 10        -- create candidates list
>         multiples 3        -- choose multiples of 3
>         multiples 5        -- choose multiples of 5 (not choosed yet)
>
>     Data under de monad is a pair of lists:
>     (validValues, CandidatesNonValidYet)
>
>
> Although my suggestion is not to use a monad for this problem, assuming
> this is a learning exercise, a solution using the state monad is as follows.

Yes, I'm trying to learn/practice Design Patterns in Haskell making 
euler problems three times:

1. Non Monad
2. Ad-hoc Monad
3. Standard Monad

Thank you for help me in the 3rd Stage. I was trying to solve 2nd Stage. :-(

> [...]

> And that should be it. If you plug these all together, you'll get 33 as
> the answer. That is the sum of [3,6,9,5,10]. I don't know why you didn't
> include 10 in the list of candidates, but if that is very important you
> can remove it by modifying makeList.

I don't included 10 because the the original problem say multiples below 
X. But as you know it isn't very important.

> Hope this helps.

Yes, a lot. I understand standard libraries are very well done. But they 
are a bit difficult to understand source code for me yet. That is the 
point of try very easy problems with ad-hoc Monads. Understand what 
problems presents Monads and how to solve.

>
> Ozgur

Jamarier.



More information about the Beginners mailing list