As described this question/answers, Functor
instances are uniquely determined, if they exists.
For lists, there are two well know Applicative instances: []
and ZipList
. So Applicative isn't unique (see also Can GHC derive Functor and Applicative instances for a monad transformer? and Why is there no -XDeriveApplicative
extension?). However, ZipList
needs infinite lists, as its pure
repeats a given element indefinitely.
- Are there other, perhaps better examples of data structures that have at least two
Applicative
instances? - Are there any such examples that only involve finite data structures? That is, like if hypothetically Haskell's type system distinguished inductive and coinductive data types, would it be possible to uniquely determine Applicative?
Going further, if we could extend both []
and ZipList
to a Monad, we'd have an example where a monad isn't uniquely determined by the data type and its Functor. Alas, ZipList
has a Monad instance only if we restrict ourselves to infinite lists (streams).
And return
for []
creates a single-element list, so it requires finite lists. Therefore:
- Are Monad instances uniquely determined by the data type? Or is there an example of a data type that can have two distinct Monad instances?
In the case there is an example with two or more distinct instances, an obvious question arises, if they must/can have the same Applicative instance:
- Are Monad instances uniquely determined by the Applicative instance, or is there an example of an Applicative that can have two distinct Monad instances?
- Is there an example of a data type with two distinct Monad instances, each having a different Applicative super-instance?
And finally we can ask the same question for Alternative/MonadPlus. This is complicated by the fact that there are two distinct set of MonadPlus laws. Assuming we accept one of the set of laws (and for Applicative we accept right/left distributivity/absorption, see also this question),
- is Alternative uniquely determined by Applicative, and MonadPlus by Monad, or are there any counter-examples?
If any of the above are unique, I'd be interested in knowing why, to have a hint of a proof. If not, an counter-example.
See Question&Answers more detail:os