I'm in the process of learning applicative functors in Haskell from learn-you-a-haskell book. But whenever I try to type in the following code into ghci:
:{
instance Applicative ZipList where
pure x = ZipList (repeat x)
ZipList fs <*> ZipList xs = ZipList (zipWith (\f x -> f x) fs xs)
:}
I get three errors:
<interactive>:137:22: error:
Not in scope: type constructor or class ‘ZipList’
<interactive>:139:9: error:
Not in scope: data constructor ‘ZipList’
<interactive>:139:24: error:
Not in scope: data constructor ‘ZipList’
I tried loading:
import Data.List
import Data.Char
I tried searching for ZipList without success.
I tried running the next few expressions without instance declaration:
getZipList $ (+) <$> ZipList [1,2,3] <*> ZipList [100,100,100]
But they also fail with the following errors:
<interactive>:142:1: error:
Variable not in scope: getZipList :: f0 Integer -> t
<interactive>:142:22: error:
Data constructor not in scope: ZipList :: [Integer] -> f0 Integer
<interactive>:142:42: error:
Data constructor not in scope: ZipList :: [Integer] -> f0 Integer
I also tried searching and found this answer: Haskell ZipList Applicative But it doesn't help me.