Why does int maxBound not work?

When i try

> Int maxBound 

in ghci i get

 Not in scope: data constructor 'Int' 

Even if I import Data.Int , the problem remains. What's going on here?

+4
source share
2 answers

EDIT: The white papers for this feature are at http://www.haskell.org/ghc/docs/7.0.3/html/libraries/base-4.3.1.0/Prelude.html#v:maxBound

First you have to do

 Prelude> maxBound :: Int 9223372036854775807 Prelude> 

If you look at a signature like maxBound :

 Prelude> :t maxBound maxBound :: (Bounded a) => a 

Then maxBound is a function that returns something like a , where a is Bounded . However, it does not accept any parameters. Int maxBound means that you are trying to create something with the Int data constructor and the maxBound parameter.

For your specific error message, you are trying to use Int - which is a type - as a value, resulting in an error. Import Data.Int will not help.

+9
source

This is an invalid Haskell.

maxBound is a constant that defines the maximum type element that is in the Bounded class :

 Prelude> :t maxBound maxBound :: Bounded a => a 

To get a binding for a specific type, you need to specialize it on a specific type. Type annotations are given by the syntax :: in expressions, for example:

 Prelude> maxBound :: Int 9223372036854775807 
+6
source

All Articles