Why would it be the same? They're different expressions.
Perhaps it simplifies things if we just look at lists. So, there's the empty list []
. Its type can be anything with brackets around it, in particular also a nested list:
Prelude> [] :: [[Int]]
[]
But there's also another "empty nested list":
Prelude> [[]] :: [[Int]]
[[]]
This one isn't really empty though, it merely contains only the empty list. ([[],[],[],...]
would also be possible). In fact, that would be the result of what you've tried, if done in the list applicative:
Prelude Control.Applicative> pure [] :: [[Int]]
[[]]
It is certainly not the same as the empty list,
Prelude> [[]] == []
False
In particular,
Prelude> (length [], length [[]])
(0,1)
And fmap
pming over an empty list never does anything, while fmap
ping over an empty-containing list will call the function with []
: an easy way to see this is
Prelude Control.Applicative> fmap undefined []
[]
Prelude Control.Applicative> fmap undefined [[]]
[* Exception: Prelude.undefined
The real confusing thing about your trials is that ghci silently uses the IO
monad.
There's also a subclass of Applicative
for actual emptiness:
Prelude Control.Applicative> :i Alternative
class Applicative f => Alternative f where
empty :: f a
(<|>) :: f a -> f a -> f a
some :: f a -> f [a]
many :: f a -> f [a]
-- Defined in `Control.Applicative'
instance Alternative [] -- Defined in `Control.Applicative'
instance Alternative Maybe -- Defined in `Control.Applicative'