When I try
> Int maxBound
in ghci, I get
Not in scope: data constructor 'Int'
Even if I import Data.Int
, still the problem persists. What is going on here?
EDIT: The official docs for the function are at http://www.haskell.org/ghc/docs/7.0.3/html/libraries/base-4.3.1.0/Prelude.html#v:maxBound
To begin with, you should be doing
Prelude> maxBound :: Int
9223372036854775807
Prelude>
If you look at the type signature of maxBound
:
Prelude> :t maxBound
maxBound :: (Bounded a) => a
Then maxBound
is a function that returns something of type a
, where a
is Bounded
. However, it does not accept any parameters. Int maxBound
means that you are trying to create something with data constructor Int
and parameter maxBound
.
For your specific error message, you are trying to use Int
- which is a type - as a value, resulting in the error you are getting. Importing Data.Int
won't help.
That's not valid Haskell.
maxBound
is a constant that defines the maximum element of types that are in the Bounded
class:
Prelude> :t maxBound
maxBound :: Bounded a => a
To get the bound for any particular type, you need to specialize it to a particular type. Type annotations are given by ::
syntax on expressions, like so:
Prelude> maxBound :: Int
9223372036854775807
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With