What you see here is a limited selection of Haskell designs. It is perfectly clear, conceptually speaking, that your Writer' type is a functor if you "leave" your first parameter. And the syntax of a programming language could be invented to allow such declarations.
The Haskell community did not do this because what they have is relatively simple and works reasonably well. This does not mean that alternative projects are impossible, but for the adoption of such a design will have to:
- Itโs no harder to put into practice what we already have;
- Offer functionality or benefits that a switch would cost.
This generalizes many other ways the Haskell communities use it; often the choice to present something as a difference of types is tied to some artifact of language design. Many monad transformers are good examples, like MaybeT :
newtype MaybeT ma = MaybeT { runMaybeT :: m (Maybe a) } instance Functor m => Functor (MaybeT m) where ... instance Applicative m => Applicative (MaybeT m) where ... instance Monad m => Monad (MaybeT m) where ... instance MonadTrans MaybeT where ...
Since this is a newtype , this means that MaybeT IO String is isomorphic to IO (Maybe String) ; you can think of two types as two โperspectivesโ in one set of values:
IO (Maybe String) is an IO action that creates values โโof type Maybe String ;MaybeT IO String is a MaybeT IO action that creates String values.
The difference between the perspectives is that they imply different implementations of Monad operations. In Haskell, then it is also associated with the following essential technical facts:
- One
String has the last type parameter ("value"), and the other Maybe String : IO and MaybeT IO have different instances for the Monad class.
But, perhaps, there is a language design where it can be said that the type IO (Maybe a) can have a specific monad for it and different from the monad for the more general type IO a . This language will have some complexity to make this distinction sequentially (for example, rules to determine which instance of Monad is the default for IO (Maybe String) and rules to allow the programmer to override the default selection). And I would modestly declare that the final result will be no less complicated than what we have. TL; DR: Fur.
Luis casillas
source share