I have a function:
powerOf :: Int -> Int -> Int
example os usage:
*Main Data.List> powerOf 100 2
2
*Main Data.List> powerOf 100 5
2
I have two questions. First - why it doesn't works:
map (powerOf 100) [2, 5]
I want to get [2, 2].
And second question. I trying to create pariatl function. Something like this:
powerOfN :: Int -> Int
powerOfN num = powerOf num
to use it such way:
let powerOf100 = powerOfN 100
powerOf100 2
powerOf100 5
but i got the error message:
simplifier.hs:31:15:
Couldn't match expected type `Int'
against inferred type `Int -> Int'
In the expression: powerOf num
In the definition of `powerOfN': powerOfN num = powerOf num
Here is full of may code:
divided :: Int -> Int -> Bool
divided a b =
let x = fromIntegral a
y = fromIntegral b
in (a == truncate (x / y) * b)
listOfDividers :: Int -> [Int]
listOfDividers num =
let n = fromIntegral num
maxN = truncate (sqrt n)
in [n | n <- [1.. maxN], divided num n]
isItSimple :: Int -> Bool
isItSimple num = length(listOfDividers num) == 1
listOfSimpleDividers :: Int -> [Int]
listOfSimpleDividers num = [n | n <- listOfAllDividers, isItSimple n]
where listOfAllDividers = listOfDividers num
powerOfInner :: Int -> Int -> Int -> Int
powerOfInner num p power
| divided num p = powerOfInner (quot num p) p (power + 1)
| otherwise = power
powerOf :: Int -> Int -> Int
powerOf num p = powerOfInner num p 0
powerOfN :: Int -> Int
powerOfN num = powerOf num
powerOf return maximum power of p in num. For example: 100 = 2 * 2 * 5 *5, so powerOf 100 2 = 2. 10 = 2 * 5, so powerOf 10 2 = 1.
How to fix errors? Thanks.