How to convert Num a => a to Int

As a beginner I want to implement such fuction: plusSecs :: Num a => a -> ClockTime -> ClockTime plusSecs n = addToClockTime ( secTimeDiff (n) ) where secTimeDiff n = TimeDiff { tdYear = 0, tdMonth = 0, tdDay = 0, tdHour = 0, tdMin = 0, tdSec = n, tdPicosec = 0 } The problem here that it's type signature is illegal because tdSec of System.Time.TimeDeff must be Int type only, but I wish to apply plusSecs to any Num or (at least) any Integral type number. The reason for this - to have less compilation errors (that are mostly about error types) and more abstractedness (generality) of this function. So, the question is: Is it possible somehow to convert any Num (or at least Integral) to Int. Please, tell me if I don't get smth in Haskell type system.

On Mar 14, 2007, at 19:30 , Sergey Perminov wrote:
So, the question is: Is it possible somehow to convert any Num (or at least Integral) to Int. Please, tell me if I don't get smth in Haskell type system.
fromIntegral. Try http://haskell.org/hoogle for searching for useful functions like this. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Moreover: from RealFrac to Int (or Integral): truncate, round, ceiling, or floor, depending on how you want to lose information. from Num to Int: there is none with such generality, since there are too many conceivable variations.
participants (3)
-
Albert Y. C. Lai
-
Brandon S. Allbery KF8NH
-
Sergey Perminov