LoginSignup
1
0

More than 5 years have passed since last update.

Int, Integer, Double

Last updated at Posted at 2013-06-30

Sometimes, ghc throws following error:

:7:21:
Couldn't match expected type Double' with actual typeInt'
In the second argument of (/)', namely(3 :: Int)'
In the expression: (10.0 :: Double) / (3 :: Int)
In an equation for `it': it = (10.0 :: Double) / (3 :: Int)

(/) required to have the same type, which is Fractional type class.

Prelude> :t (/)
(/) :: Fractional a => a -> a -> a
Prelude> :i Int
data Int = GHC.Types.I# GHC.Prim.Int#   -- Defined in `GHC.Types'
instance Bounded Int -- Defined in `GHC.Enum'
instance Enum Int -- Defined in `GHC.Enum'
instance Eq Int -- Defined in `GHC.Classes'
instance Integral Int -- Defined in `GHC.Real'
instance Num Int -- Defined in `GHC.Num'
instance Ord Int -- Defined in `GHC.Classes'
instance Read Int -- Defined in `GHC.Read'
instance Real Int -- Defined in `GHC.Real'
instance Show Int -- Defined in `GHC.Show'

fromIntegral helps to convert Integer or Int to Num.

Prelude> :t fromIntegral 
fromIntegral :: (Integral a, Num b) => a -> b

Still Num is not Fractional.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0