3

I am learning Haskell and trying to use exact Rational numbers. I have the the following simple Haskell code:

import Ratio

x :: Rational
x = 5 % 2

When I load this in WinHugs, everything is fine. However, when I load it in ghci, I get the following error message:

E:\devel\src\haskell\rational.hs:1:8:

Could not find module `Ratio'
It is a member of the hidden package `haskell98-2.0.0.1'.
Use -v to see a list of the files searched for.

Failed, modules loaded: none.

Why am I getting this error?

Also, all the hits google gives me for rational numbers in Haskell seem to be out of date. What is the current way to do exact arithmetic with rational numbers?

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

1 Answers1

6

The haskell98 library is deprecated in the Haskell Platform. You should adapt to the haskell2010 standard, which defines rational numbers to be in Data.Ratio.

dflemstr
  • 25,947
  • 5
  • 70
  • 105
  • Thanks for the info. I should have mentioned that I am just learning Haskell, so I want to learn the "right" way to do it. – Code-Apprentice Jul 24 '12 at 15:44
  • The `Data.Ratio` module is perfectly fine to use. There is no other library that I know of for dealing with rational numbers. – dflemstr Jul 24 '12 at 15:45
  • As you said, I was trying to use the deprecated haskell98 library. My last comment was in response to the word "adapt" in your answer. I'm not adapting so much as learning from scratch, which I didn't exactly make clear in my question. – Code-Apprentice Jul 24 '12 at 15:58
  • Oh, I understand. I thought that you didn't think `Data.Ratio` was the "best" module to use, since it basically is a copy of the (now aged) `Ratio` module. – dflemstr Jul 24 '12 at 15:59
  • I find it strange that google primarily gave me hits for the old Ratio module. It looks like only the second link was for Data.Rato ;-( – Code-Apprentice Jul 24 '12 at 16:02
  • 1
    @Code-Guru Use hoogle, http://www.haskell.org/hoogle, to look for Haskell related functions/types. – augustss Jul 24 '12 at 16:04
  • @augustss Sweet! Thanks for the tip. – Code-Apprentice Jul 24 '12 at 16:06