AW: [Haskell] Hugs Nov2003 X Nov2002
try fromInt = fromInteger . toInteger Markus -- Markus Schnell -----Ursprüngliche Nachricht----- Von: haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] Im Auftrag von Stenio Gesendet: Dienstag, 16. März 2004 10:29 An: Ketil Malde Cc: haskell@haskell.org Betreff: Re: [Haskell] Hugs Nov2003 X Nov2002 fromInteger works, but it converts from Integer to Float. In my script, I need fromInt because it converts from Int to Float. Example: average :: Int -> Float average n = fromInt ( sum n ) :: Float / fromInt n :: Float It works only in Hugs November 2002 Stenio. --------- Mensagem Original -------- De: "Ketil Malde" <ketil+haskell@ii.uib.no> Para: "Stenio" <stenio@uesb.br> Cópia: haskell@haskell.org Assunto: Re: [Haskell] Hugs Nov2003 X Nov2002 Data: 16/03/04 12:07 "Stenio" <stenio@uesb.br> writes:
I was using Hugs November 2002 and the function fromInt works fine, but in the version November 2003 the same function doesn´t work.
I'm too lazy to check the standard, so I'll just assume Hugs was wrong. I think the solution is to use "fromIntegral" instead. GHCi also has "fromInteger", although I'm not quite sure why we need this in addition to "fromIntegral"? (Possibly because it is a member of Num, and it would break too much code to remove it) -kzm -- If I haven't seen further, it is by standing in the footprints of giants
hi, i believe you should use fromIntegral :: (Integral a, Num b) => a -> b Since Int is in the Integral class, and Float is in the Num class this should do exactly the job you need. For the other functions that were not working --- they were moved to the Char module, so you need to add "import Char" at the top of your program. Markus.Schnell@infineon.com wrote:
try
fromInt = fromInteger . toInteger
this does not seem like a good idea, as you start with an Int, then convert it to an Integer, and then you make a Float out of that. seems like a waste. hope this helps -iavor
Markus
-- Markus Schnell
-----Ursprüngliche Nachricht----- *Von:* haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] *Im Auftrag von *Stenio *Gesendet:* Dienstag, 16. März 2004 10:29 *An:* Ketil Malde *Cc:* haskell@haskell.org *Betreff:* Re: [Haskell] Hugs Nov2003 X Nov2002
fromInteger works, but it converts from Integer to Float. In my script, I need fromInt because it converts from Int to Float.
Example:
average :: Int -> Float average n = fromInt ( sum n ) :: Float / fromInt n :: Float
It works only in Hugs November 2002
Stenio.
--------- Mensagem Original -------- De: "Ketil Malde" <ketil+haskell@ii.uib.no> Para: "Stenio" <stenio@uesb.br> Cópia: haskell@haskell.org Assunto: Re: [Haskell] Hugs Nov2003 X Nov2002 Data: 16/03/04 12:07
"Stenio" <stenio@uesb.br> writes:
> I was using Hugs November 2002 and the function fromInt works fine, > but in the version November 2003 the same function doesn´t work.
I'm too lazy to check the standard, so I'll just assume Hugs was wrong. I think the solution is to use "fromIntegral" instead. GHCi also has "fromInteger", although I'm not quite sure why we need this in addition to "fromIntegral"? (Possibly because it is a member of Num, and it would break too much code to remove it)
-kzm -- If I haven't seen further, it is by standing in the footprints of giants
------------------------------------------------------------------------
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (2)
-
Iavor S. Diatchki -
Markus.Schnell@infineon.com