#4159: move Monad and MonadFix instances for Either from mtl to
base
Claus Reinke
claus.reinke at talk21.com
Wed Jun 30 16:57:19 EDT 2010
The current proposal is not trying to fix the fail situation, so
this is a bit off topic, but to answer your question:
> So I prefer 'case xyz of { pat -> mzero/throw/whatever }'. It's more
> wordy but clearer. Are there uses out there that really rely on the
> conciseness afforded by refutable patterns?
The stand-alone alternative is more like
do { p1 <- return x; return e1 }
vs
case x of { p1 -> return e1; _ -> mzero}
which doesn't look much worse until you realize that the
former embeds nicely into existing monadic code, the latter
doesn't. So it becomes
do { ..; p1 <- return x; .. }
vs
do { ..; case x of { p1 -> ..; _ -> mzero } }
and so on for every added pattern.
When I embed Haskell-Coloured Petri Nets in Haskell, the
former style can be made to resemble the input language
quite closely (changing from graphical to textual
representation, but with easily recognizable structure).
When writing combinator parsers, type system rules, or
other rule-based embedded languages that embed into
a MonadPlus, it can be similarly helpful to write down
only the interesting success cases, without messing up
the code with standard failure cases.
Claus
More information about the Libraries
mailing list