[Haskell-cafe] are Monads with slightly stricter types in instances
still Monads?
Julien Oster
haskell at lists.julien-oster.de
Tue Jan 30 12:31:19 EST 2007
Hello,
The type of the monadic bind function in the Monad class is
Monad m => m a -> (a -> m b) -> m b
Now, would it be possible to create a monad with a slightly stricter
type, like
StrictMonat m => m a -> (a -> m a) -> m a
and, accepting that all steps of the computation would be bound to
operate on the same type, would this be without any undesirable
implications?
For the sake of understanding monads better, I tried to write several
custom monads which may or may not be useful. Among those were:
* The Tracker Monad - tracks every result of every step of the
sequential computation in a (normal, stricly typed) list inside
of the monad
* The Goto Monad - sequential computation that allows restarts of
the computation at arbitrarily set labels within it
But Haskell doesn't like those. Rightly so, because the bind function
would have the stricter type mentioned above.
[Otherwise the Tracker monad would have to store values of different
types in its list and the Goto monad would encounter restarts at labels
that process different types of the value than what has been computed so
far. Both doesn't make sense.]
I still have to prove wether those two monads follow the monadic laws at
all, but that's part of my exercise. But let's say they follow the laws
(I'm pretty sure that at least the Tracker monad does), is there
anything else that would prevent the stricter typing from being legal or
useful? Maybe I'm missing something simple.
And would I still be able to use Haskell's "do" syntax? My first guess
is yes, because it really just seems to translate into normal syntax.
Thanks,
Julien
More information about the Haskell-Cafe
mailing list