Proposal: In haskell-src, add Functor, Applicative, Monad, and Monoid instances for ParseResult

In the haskell-src package, add the following instances to ParseResult that make it more convenient to traverse and modify a syntax tree. http://hackage.haskell.org/trac/ghc/ticket/3290 Two weeks discussion period.
instance Functor ParseResult where fmap f (ParseOk x) = ParseOk $ f x fmap f (ParseFailed loc msg) = ParseFailed loc msg
instance Applicative ParseResult where pure = ParseOk ParseOk f <*> x = f <$> x ParseFailed loc msg <*> _ = ParseFailed loc msg
instance Monad ParseResult where return = ParseOk ParseOk x >>= f = f x ParseFailed loc msg >>= _ = ParseFailed loc msg
instance Monoid m => Monoid (ParseResult m) where mempty = ParseOk mempty ParseOk x `mappend` ParseOk y = ParseOk $ x `mappend` y ParseOk x `mappend` err = err err `mappend` _ = err -- left-biased

On Wed, Jun 10, 2009 at 9:32 PM, Yitzchak Gale
In the haskell-src package, add the following instances to ParseResult that make it more convenient to traverse and modify a syntax tree.
http://hackage.haskell.org/trac/ghc/ticket/3290
Two weeks discussion period.
Thanks a lot Yitzchak - I've applied this patch to haskell-src-exts (with no discussion period at all ;-)). Why use haskell-src...? :-) Cheers, /Niklas

Niklas Broberg wrote:
I've applied this patch to haskell-src-exts
Glad it could be of use there too.
Why use haskell-src...? :-)
In this case, I needed simplicity, and I didn't need the extensions. Regards, Yitz

Hi Yitz
I use haskell-src-exts as a matter of course, not for the extensions
but for the fact that its maintained, released, disjoint from base and
has always served my needs brilliantly. Extensions aren't something I
really even considered, but they seem to turn out to be useful now and
then.
Thanks, Neil
On Wed, Jun 10, 2009 at 10:43 PM, Yitzchak Gale
Niklas Broberg wrote:
I've applied this patch to haskell-src-exts
Glad it could be of use there too.
Why use haskell-src...? :-)
In this case, I needed simplicity, and I didn't need the extensions.
Regards, Yitz _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Niklas Broberg wrote:
Why use haskell-src...? :-)
I wrote:
In this case, I needed simplicity, and I didn't need the extensions.
Neil Mitchell wrote:
I use haskell-src-exts as a matter of course, not for the extensions but for the fact that its maintained, released, disjoint from base and has always served my needs brilliantly. Extensions aren't something I really even considered, but they seem to turn out to be useful now and then.
All points well taken, thanks. In this particular case, the additional complexity of the Syntax types in haskell-src-exts would cause a bit more pain, but it is still an option. Regards, Yitz
participants (3)
-
Neil Mitchell
-
Niklas Broberg
-
Yitzchak Gale