thepen
thepen

Reputation: 371

Understanding (1+)

the type of 1+ is given as :

Prelude> :t (1+)
(1+) :: Num a => a -> a

Is the correct way to read this function as :

1+ takes a Num and returns a function of type a -> a ?

Upvotes: 1

Views: 296

Answers (3)

Miguelme
Miguelme

Reputation: 629

No, in Haskell the part before the => means the class constraint to which a parameter has to be an instance of. So,

(1+) :: Num a => a -> a 

It means (1+) is a function that takes a parameter "a" and returns a parameter "a" where the parameter "a" has to be an instance of the class constraint Num.

Here you can see the entire definition of the Num class constraint: http://hackage.haskell.org/package/base-4.9.0.0/docs/Prelude.html#t:Num

Upvotes: 0

ThreeFx
ThreeFx

Reputation: 7360

No, Num a is a class constraint, which is implied by the different arrow (=>).

+1 is a function from a to a where a must be an instance of the Num typeclass.

For more information see the part of Learn you a Haskell.

Upvotes: 4

sepp2k
sepp2k

Reputation: 370425

1+ takes an a and returns an a with the restriction that a must be an instance of Num.

Upvotes: 5

Related Questions