softshipper
softshipper

Reputation: 34071

Confuse about pure in applicative functor

I have following example with pure function:

Prelude> :t pure ((+1) 1)
pure ((+1) 1) :: (Num a, Applicative f) => f a

What is above the concrete type of f wrapped a?

For example, the f(structure) is here Maybe:

Prelude> pure ((+1) 1) :: Maybe Int
Just 2

and what is the structure of:

pure ((+1) 1)

?

The second example:

Prelude> :t pure ((+1) 1) :: [Int]
pure ((+1) 1) :: [Int] :: [Int]

Why does the GHCi show the type twice, namely :: [Int] :: [Int] not only :: [Int]?

Upvotes: 0

Views: 81

Answers (1)

melpomene
melpomene

Reputation: 85767

  1. f and a are both type variables. There is no concrete type. It will use whatever type is required by the surrounding context.

  2. When you type :t EXPR, ghci prints the type as EXPR :: TYPE. The first :: [Int] is part of the expression you typed; the second :: [Int] is the type computed by ghci.

Upvotes: 4

Related Questions