[Haskell-cafe] Help with generalizing function

leledumbo leledumbo_cool at yahoo.co.id
Wed Jun 25 04:05:12 EDT 2008


Hi, I'm back. I have some troubles understanding your code:

Chaddaï Fouché-2 wrote:
> 
> findAllAns 0 0 = [[]]
> findAllAns 0 s = []
> findAllAns n s = [ x:xs | x <- [0..s], xs <- findAllAns (n - 1) (s - x) ]
> 

Let's try a test case (CMIIW) for findAllAns 2 1:
findAllAns 2 1 = [ 0:(findAllAns 1 1) ]
                   = [ 0:0:(findAllAns 0 1) ]
                   = [ 0:0:[] ] // Not a solution
                   
                   = [ 0:(findAllAns 1 1) ]
                   = [ 0:1:(findAllAns 0 0) ]
                   = [ 0:1:[[]] ] // A solution

                   = [ 1:(findAllAns 1 0) ]
                   = [ 1:0:(findAllAns 0 0) ]
                   = [ 1:0:[[]] ] // A solution

                      ( 1:1:? is never reached. )

I don't understand why if the last element is [[]] then it's included in the
result and not if it's [].
-- 
View this message in context: http://www.nabble.com/Help-with-generalizing-function-tp18063291p18106999.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list