[Haskell-beginners] What is the best practice for code]

Austin Wood bonfyre at gmail.com
Tue Nov 10 19:50:03 EST 2009

On Tue, Nov 10, 2009 at 8:46 AM, legajid <legajid at free.fr> wrote:
> i wanted to write a program that searches for all combinations of some
> numbers, the sum of which is a given value.
> So, i started writing my program, creating a function for each separate
> phase : creating list of triples, selecting valuable ones, filtering the
> result.
> Looking at my code, i've reduced it several ways; the last version holds on
> one single line of code.
> Please, from the 3 versions i established, which one is " better"? What are
> the criterias of a "good" code ?
> What about using many anonymous functions?
> I think there are other solutions than those i propose.

It could be done using do;

import Control.Monad

numbers = [9,8..1]
f = do x <- numbers
       y <- numbers
       z <- numbers
       guard (y < x && z < y)
       guard (x+y+z == 19)
       return [x,y,z]

More information about the Beginners mailing list