haskell - Using guards after assigning some variables first -


i know can this...

iszero :: int -> bool iszero x   | x == 0      = true   | otherwise   = false 

but can this?

ispalindrome :: int -> bool ispalindrome x   let digitlist = inttodigits x -- decomposes integer                                 -- digits, i.e. 37 -> [3, 7]   | digitlist == reverse digitlist                = true   | otherwise                                     = false 

this result in compilation errors, i'm sure know i'm trying do.

use where clause instead

ispalindrome :: int -> bool ispalindrome x     | digitlist == reverse digitlist = true     | otherwise                      = false     digitlist = inttodigits x 

of course, example skip guards , write

ispalindrome x = digitlist == reverse digitlist     digitlist = inttodigits x 

Comments