Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Integer arithmetic in Haskell

  1. Dec 28, 2004 #1
    Can anybody explain what appear to be discrepancies in the way the following expressions are interpreted by Hugs (Haskell98 mode) ?

    Code (Text):

    Main> div -6 4
    ERROR - Cannot infer instance
    *** Instance   : Num (b -> a -> a -> a)
    *** Expression : div - fromInt 6 4

    Main> div (-6) 4
    -2
    Main> -6 `div` 4
    -1
    Main> (-6) `div` 4
    -2
     
     
  2. jcsd
  3. Dec 28, 2004 #2
    Never mind.

    I guess it must be right-associative, so -6 `div` 4 is interpreted as -(6 `div` 4).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Integer arithmetic in Haskell
Loading...