Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does not Int maxBound work?

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?

like image 975
Eli Avatar asked Apr 24 '11 02:04

Eli


2 Answers

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.

like image 78
li.davidm Avatar answered Oct 19 '22 20:10

li.davidm


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
like image 24
Don Stewart Avatar answered Oct 19 '22 18:10

Don Stewart