I am trying to write a function called check that when applied to n returns a Bool indicating whether the ∑r=0 to n (n choose r) = 2^n
I have made the factorial and choose functions which work but I am having difficulty understanding what the type would be for the check function. I have written what I have done for it and I think logically it might work but I am not sure. The error I get when running says 'couldn't match type a -> Bool to actual type Bool' but I am not entirely sure how to make it an actual Bool type.
factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)
choose :: (Integral a) => a -> a -> a
n `choose` r
| r < 0 = 0
| r > n = 0
| otherwise = factorial n `div` (factorial r * factorial (n-r))
check :: (Integral a) => a -> a -> Bool
check n = (if (factorial (choose n)) == 2^n then True else False)
a->a->Booltakes two arguments, but you only need one. 2) Try a list comprehension e.g.sum [ ... | r<-[0..n] ] == 2^n. 3) Never useif condition then True else False-- it's equivalent to justcondition, only more complex to read.if (factorial (choose n)) == 2^n then True else Falseis equivalent to just writing:factorial (choose n) == 2^nchoosetakes two arguments, but you have given it only one infactorial (choose n); perhaps this is related to the problem you are having. Where is the code reflection incheckofr, and its bounds of0ton, and the summation of the results? What math is being reflected by thefactorialincheck?