First, the question arises: does the statement “all lists have length” have one operator or a series of operators “list1 has length”, “list2 has length”, ...?
If you specify type f with explicit forall , you get f :: forall a. a -> Int f :: forall a. a -> Int . First of all, it is not "high ranking". At GHCI, we can do the following:
λ> :set -XRankNTypes λ> :k (forall a. a -> Int) (forall a. a -> Int) :: *
So f has the form * .
Now, in Haskell, we can use ~ for type equality. We can set the following to check the material in GHCI:
λ> :set -XImpredicativeTypes λ> :set -XTypeFamilies λ> :t undefined :: ((~) Int Int) => a undefined :: ((~) Int Int) => a :: a
This shows that the GHC has figured out type equality for this example. Type inequality will give the following error:
λ> undefined :: ((~) (Int -> Int) (Int)) => a <interactive>:22:1: Couldn't match expected type 'Int' with actual type 'Int -> Int' In the expression: undefined :: ((~) (Int -> Int) (Int)) => a In an equation for 'it': it = undefined :: ((~) (Int -> Int) (Int)) => a
Now using this method directly will not allow us to compare the type f , but I found a small option that should work for our purposes:
λ> :t undefined :: forall a. ((a -> Int) ~ (Int -> Int)) => a undefined :: forall a. ((a -> Int) ~ (Int -> Int)) => a :: Int
In other words, if f equivalent to the type g :: Int -> Int , then a must be Int. This is similar to x = y , y = 0 , so x = 0 . We do not have x = 0 , until we specify y = 0 , until we just have x = y .
Maybe different in that it has the following form:
λ> :k Maybe Maybe :: * -> *
Since we use DataKinds , we have :k (~) :: k -> k -> GHC.Prim.Constraint , so we can do things like:
λ> :t undefined :: (~) Maybe Maybe => Int undefined :: (~) Maybe Maybe => Int :: Int λ> :k Either () Either () :: * -> * λ> :t undefined :: (~) Maybe (Either ()) => Int Couldn't match expected type 'Either ()' with actual type 'Maybe'
To summarize, f :: forall a. a -> Int f :: forall a. a -> Int has the same meaning as the statement "if you give me something, I will give you Int." Could you translate the expression into a bunch of sayings "if you give me a dog ...", "if you give me a penny ..."? Yes, but it weakens the statement. In the end, decide exactly what you mean by “the same,” and get an answer.