[Haskell-cafe] How to spot Monads, Applicatives ...
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Jun 18 08:37:56 UTC 2016
On Sat, Jun 18, 2016 at 10:31:54AM +0200, martin wrote:
> Suppose I came to the conclusion that "s->(s,a)" is useful to model
> stateful computations. Next I want want to make it a Functor. This
> raises two questions:
>
> (1) Why do I want to do this in the first place?
"s -> (s, a)" simply *is* functorial in 'a'. There's no "want" about that
part. From that point on it's just a minor question of whether you want to
write out a Functor instance so you can conveniently use that fact as part
of the programs you write.
> (2) What keeps me from trying "instance Functor (MyState a)" instead of
> "instance Functor (MyState s)? Is trying it the wrong way and failing the
> only way to make that choice? I suppose there must be some reasoning
> which is closer to the problem.
You mean 'instead of "instance Functor (State s)"'. The answer is that 's'
appears on the left hand side of the arrow in "s -> (s, a)" so there's no
way the 's' type parameter can be functorial.
Tom
More information about the Haskell-Cafe
mailing list