Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Type signature faggotry

Name: Anonymous 2007-04-12 15:27 ID:yhED11h4

I have this function:

secondsToUnit seconds n = let multiplier = foldl1 (*) [ [1,60,60,24] !! x | x<-[0..n] ]
                              units = floor $ seconds / multiplier
                              rest = seconds - units * multiplier
                          in
                          (units, rest)


When I try to use it somewhere, GHC complains:

|code]    Ambiguous type variable `a' in the constraints:
      `RealFrac a' arising from use of `secondsToUnit'
      `Integral a' arising from use of `secondsToUnit'
    Probable fix: add a type signature that fixes these type variable(s)[/code]

The problem is, I'm still a newbie and I have no idea what kind of type signature I should use, since I don't completely understand Haskell's numeric types yet. Any pointers? Can it even be fixed just by adding a proper type signature or is there something else I need to alter?

Name: Anonymous 2007-04-12 15:36 ID:dGWuDF8G

>>1
The compiler complains because you use /, which is defined in both the RealFrac and Integral classes -- you'll have to help the type inference engine a little here by explicitly specifying types of something... the function itself is a good start.

Or, that's my guess, at least ;)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List