<div dir="auto"><div>It is because (**) takes floating point numbers. In your first equation both 4s are different. The second 4 is an Integer but the first is a some Floating type aka 4.0.</div><div dir="auto"><br></div><div dir="auto">In your second equation, both of those numbers are constrained to whatever type i is, and fact demands an Integer and (**) demands a Float or Double or some other Floating type, which cannot be reconciled.</div><div dir="auto"><br></div><div dir="auto">You should be able to fix this with (untested)  x**fromIntegral(i), which converts i from an Integer to Num and all Floating are Nums.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, Nov 30, 2022, 19:41 Jonathan Drews <<a href="mailto:jondrews@fastmail.com" rel="noreferrer noreferrer" target="_blank">jondrews@fastmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Folks:<br>
<br>
 I am using Glasgow Haskell Compilation System, version 9.2.4 on<br>
OpenBSD 7.2. I am stumped by the following problem. If I run the<br>
following program in ghci, then it works fine. Look:<br>
<br>
fact :: Integer -> Integer<br>
fact n = product [1..n]<br>
<br>
<br>
term :: Double -> Double<br>
term x  = x**4/fromIntegral(fact(4))<br>
<br>
$ ghci<br>
GHCi, version 9.2.4: <a href="https://www.haskell.org/ghc/" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">https://www.haskell.org/ghc/</a>  :? for help<br>
ghci> :l seriesTermTest.hs <br>
[1 of 1] Compiling Main             ( seriesTermTest.hs, interpreted )<br>
Ok, one module loaded.<br>
ghci> term 1.0<br>
4.1666666666666664e-2<br>
<br>
However if I use fromIntegral inside a list comprehension like so:<br>
<br>
fact :: Integer -> Integer<br>
fact n = product [1..n]<br>
<br>
<br>
expon :: Double -> Double<br>
expon x  = sum [x**i/fromIntegral(fact(i)) | i <- [0..50]]<br>
<br>
then I get the following error message:<br>
<br>
$ ghci                         <br>
GHCi, version 9.2.4: <a href="https://www.haskell.org/ghc/" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">https://www.haskell.org/ghc/</a>  :? for help<br>
ghci> :l ePowerSeries.hs <br>
[1 of 1] Compiling Main             ( ePowerSeries.hs, interpreted )<br>
<br>
ePowerSeries.hs:6:40: error:<br>
    * Couldn't match expected type `Integer' with actual type `Double'<br>
    * In the first argument of `fact', namely `(i)'<br>
      In the first argument of `fromIntegral', namely `(fact (i))'<br>
      In the second argument of `(/)', namely `fromIntegral (fact<br>
(i))'<br>
  |<br>
6 | expon x  = sum [x**i/fromIntegral(fact(i)) | i <- [0..50]]<br>
  |                                        ^<br>
Failed, no modules loaded.<br>
<br>
What am I doing wrong?<br>
<br>
--<br>
Kind regards,<br>
Jonathan<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" rel="noreferrer noreferrer noreferrer" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div></div>