I'm trying to write Applicative for this type
data Choice a = ColumnA a | ColumnB a
I wrote a Functor instance:
instance Functor Choice where
fmap f (ColumnA a ) = (ColumnA (f a) )
fmap f (ColumnB a ) = (ColumnB (f a) )
Now I want to write Applicative where ColumnB is considered "a correct value" and ColumnA is considered to be some kind of an error.
I tried
instance Applicative Choice where
pure = ColumnB
ColumnB f <*> r = fmap f r
ColumnA f <*> _ = ColumnA f --- this does not work
How can I make it work ?