Panicos
Panicos

Reputation: 311

What do types mean in haskell

I got asked this question in a class that left me pretty confused, we were presented with the following:

For the bellow type declarations:

ranPositions :: Image -> Dims -> [Point] 
getBlockSums :: Image -> Dims -> [Point] -> [BlockSum]
i :: Image
d :: Dims

What are the types of the following ? isn't it the above?!

ranPositions i d
getBlockSums i d

So what I responded was this:

type ranPositions = Array Point Int, (Int, Int)
type getBlockSums = Array Point Int, (Int, Int)

// Because (this was given)

type Image = Array Point Int 
type Dims = (Int, Int)

Apart from being wrong, this question confused me because i thought the type of a function was what was declared after the :: and therefore it had been already given, no?

I could do with a bit of explaining and I will really appreciate any help.

Upvotes: 2

Views: 192

Answers (2)

Matt Ellen
Matt Ellen

Reputation: 11592

The type of ranPosition i d is [Point] - (currying gives you a function that returns [Point])

The type of getBlockSums i d is [Point] -> [BlockSum] - (currying gives you a function that returns a function from [Point] to [BlockSum])

Upvotes: 8

Ingo
Ingo

Reputation: 36329

Sure, but they asked for the types of expressions, not functions.

Is it not obvious that the type of the following expressions:

foo 
foo a
foo a b

must all be different? If this is not clear to you, then go back and read about function application.

Upvotes: 3

Related Questions