Haskell import error: not in scope

I wrote this code:

import GHC.Float                                                                 

next :: GHC.Float -> GHC.Float-> GHC.Float                                         
next n x = (x + n / x) / 2

And I get the following error:

numerical.hs:3:9:
    Not in scope: type constructor or class `GHC.Float'

numerical.hs:3:22:
    Not in scope: type constructor or class `GHC.Float'

numerical.hs:3:34:
    Not in scope: type constructor or class `GHC.Float'

The module is imported without any problems, so I'm not sure if I refer to it with the wrong name or if the standard Float module matches the IEEE GHC.Float, and there is no need to explicitly import it.

I tried to do import GHC.Float as Flwithout success - I got an error of the same type on Fl.

I'm just starting Haskell (obviously), so any help is appreciated!

+4
source share
1 answer

You do not need to import GHC.Floatmanually, you can just write Float, for example

next :: Float -> Float -> Float
next n x = (x + n / x) / 2

GHC Prelude , . Prelude , , "" . , Int, Float, Maybe, IO , head, +, / ..


, IEEE isIEEE GHC.Float:

import GHC.Float

main = do
    putStr "1.0 is an IEEE floating point: "
    print $ isIEEE (1.0 :: Float)

, True


, , , , import , . , import qualified, :

import GHC.Float -- Everything now in scope
import qualified Data.Maybe -- Have to use full name
import qualified Data.List as L -- aliased to L

main = do
    -- Don't have to type GHC.Float.isIEEE
    print $ isIEEE (1.0 :: Float)
    -- Have to use full name
    print $ Data.Maybe.isJust $ Nothing
    -- Uses aliased name
    print $ L.sort [1, 4, 2, 5, 3]
+5

All Articles