[Haskell-cafe] How to convert Num a => a to Int

Sergey Perminov sv.perminov at gmail.com
Wed Mar 14 19:30:34 EDT 2007


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.


More information about the Haskell-Cafe mailing list