Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: Numeric types

Following are the basic Numeric Types supported by Haskell. All these numeric types are instances of Num.

It is bounded Integer type, represent integer values, For 32-bit machines the range goes from -2147483648 to 2147483647. For 64-bit machine the range goes from -9223372036854775808 to 9223372036854775807
It is unbounded integer type, represent arbitrarily large integer values. Size is limited by the amount of memory available on your machine.
Single Precision Floating Point value. Used to Represent Real Numbers like 10.32, 9.86 etc., Usage of Float is discouraged, since Haskell compilers are written Double data type efficient code.
Double precision floating point value. Used to represent real numbers like 10.32, 9.86 etc.,

Following code snippet gives you the maximum and minimum values of Int type.

biggestInt, smallestInt :: Int
biggestInt = maxBound
smallestInt = minBound

Prelude> :load variable.hs
[1 of 1] Compiling Main ( variable.hs, interpreted )
Ok, modules loaded: Main.
*Main> biggestInt
*Main> smallestInt

When a function signature supports a type T, then it can able to support all the child types of type T.

For example,
Prelude> :t (+)
(+) :: Num a => a -> a -> a

Operator + takes any variable of type Num, so it can support all sub types like Int, Integer, Float, Double.
Prelude> 10 + 90.09
Prelude> 10.01+100.98
Prelude> 10.01+987

Previous                                                 Next                                                 Home

This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: Numeric types


Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription