
Oh I get it. I should use a type variable 's' instead of String.
instance Applicative (Either s) where pure x = Right x Right g <*> Right x = Right (g x) Right _ <*> Left s = Left s Left s <*> _ = Left s
I guess there is already a functor instance of Either s? Interesting how functors and applicative functors can be thought of as containers, but one thing that makes them flexible is that they can contain zero, one, or many pieces of data (depending on the functor), and they can contain something of a different sort entirely (like Left). Is it possible to make an applicative functor that contains auxiliary data unrelated to the "main" data. I think not, because then there's no way to define pure. Michael Mossey wrote:
Why does the following give me an error unless I enable FlexibleInstances?
instance Applicative (Either String) where pure x = Right x Right g <*> Right x = Right (g x) Right _ <*> Left s = Left s Left s <*> _ = Left s _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners