title: "Converting" Double to Int
body: <p>I want to write a function that calculates change when given an amount of coins. It has worked great except when I actually want the input to be a Double rather than Int.</p>
  
  <p>This is my code</p>
  
  <pre><code>coins::[Int]
  coins = [200, 100, 50, 20, 10, 5, 2, 1]
  change::Int-&gt;[Int]-&gt;[Int]
  change n [] = []
  change n coins
           | n == 0 = []
           | n &gt;= firstcoin = firstcoin:change (n-firstcoin) coins  
           | otherwise = change n (tail coins)
           where firstcoin = head coins
  </code></pre>
  
  <p>This works nice and all, but when I try changing the code to:</p>
  
  <pre><code>change::Double-&gt;[Int]-&gt;[Int]
           | (n*100) == 0 = []
           | (n*100) &gt;= firstcoin = firstcoin:change (n-firstcoin) coins
           | otherwise = change n (tail coins)
           where firstcoin = head coins
  </code></pre>
  
  <p>The following happens:</p>
  
  <pre><code>  [1 of 1] Compiling Main             ( coin.hs, interpreted )
  
    coin.hs:7:27:
    Couldn't match expected type ‘Double’ with actual type ‘Int’
    In the second argument of ‘(&gt;=)’, namely ‘firstcoin’
    In the expression: (n * 100) &gt;= firstcoin
  
    coin.hs:7:59:
    Couldn't match expected type ‘Double’ with actual type ‘Int’
    In the second argument of ‘(-)’, namely ‘firstcoin’
    In the first argument of ‘change’, namely ‘(n - firstcoin)’
    Failed, modules loaded: none.
  </code></pre>
  
  <p>Is this like using "/" where I have to use fromIntegral beforehand? If so, how does that translate here?</p>
  
  <p>*A little side question: how can I make the list of coins written here "embedded" into the function so that the signature would look like:</p>
  
  <pre><code>change::Int-&gt;[Int]
  </code></pre>
  
  <p>(in other words, I don't want to explicitly write in the list for it to work. Would I need to change my whole code?)</p>