The confusion stems from using the same name for data and type; a common and accepted, even recommended practice for all but the very novice Haskellers.
For now, you can use different names, to reduce the cognitive load while learning and getting accustomed to Haskell's data type declarations:
data Twice a = MkTwice a a deriving (Show) -- 'Mk' is for "make"
-- Twice a -- a type
-- MkTwice :: a -> a -> Twice a -- data constructor
instance Functor Twice where
-- fmap (f :: a -> b) :: Twice a -> Twice b
fmap f (MkTwice x y) = MkTwice (f x) (f y) -- transform both fields
instance Applicative Twice where
pure x = MkTwice x x -- create two fields from one value
MkTwice f g <*> MkTwice x y = MkTwice (f x) (g y) -- combine both fields
Twice a is a type, with a a type variable.
MkTwice is the data constructor for this type. It makes values of type Twice a, from two values of type a (say, x :: a and y :: a). Values appear to the right of = in Haskell definitions (roughly).
It is also used in patterns for values of the type Twice a. Patterns appear to the left of = in Haskell definitions. There can be no duplicate pattern variables in Haskell's patterns. Each pattern variable stands for some value.
Each type variable stands for a type.
I bet you wouldn't make those mistakes if you were using the different names for the type and data constructor.