简体   繁体   中英

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] ?

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM