I am new to haskell and am trying to learn why certain things do not compile in haskell. For example, I get the following error:
• Couldn't match expected type ‘Int -> Float’
with actual type ‘Float’
• Possible cause: ‘(/)’ is applied to too many arguments
In the expression: (fromIntegral x :: Float) / 100.0
In an equation for ‘percent’:
percent x = (fromIntegral x :: Float) / 100.0
For this code:
percent :: Int -> Int -> Float
percent x = (fromIntegral x :: Float) * 100.0
Or something like this:
percent :: Int -> Int -> Float
percent x = a * 100.0
where a = fromIntegral x :: Float
While, this method works, that I found on this post, that is slightly more complex as it divides two ints before it multiplies the 100? It follows a similar methodology as the ones I coded as well that involve only one int multiplied by 100. The second one I coded, I modeled after the code seen below. I'm not confused as to why the above do not work, however, the one below that is doing a similar thing works.
percent :: Int -> Int -> Float
percent x y = 100 * ( a / b )
where a = fromIntegral x :: Float
b = fromIntegral y :: Float
I would appreciate the assistance as I am new to Haskell and still trying to learn how it operates.