On Mon, Feb 25, 2013 at 11:13 AM, Simon Hengel <sol@typeful.net> wrote:
On Mon, Feb 25, 2013 at 09:57:04AM +0100, Joachim Breitner wrote:
> Hi,
>
> Am Montag, den 25.02.2013, 08:06 +0200 schrieb Michael Snoyman:
> > Quite a while back, Simon Hengel and I put together a proposal[1] for
> > a new feature in GHC. The basic idea is pretty simple: provide a new
> > pragma that could be used like so:
> >
> > error :: String -> a
> > errorLoc :: IO Location -> String -> a
> > {-# REWRITE_WITH_LOCATION error errorLoc #-}
>
> in light of attempts to split base into a pure part (without IO) and
> another part, I wonder if the IO wrapping is really necessary.
>
> Can you elaborate the reason why a simple "Location ->" is not enough?

The IO helps with reasoning.  Without it you could write code that does
something different depending on the call site.  Here is an example:


    someBogusThingy :: Int
    someBogusThingy = ..

    someBogusThingyLoc :: Location -> Int
    someBogusThingyLoc loc
      | (even . getLine) loc = 23
      | otherwise            = someBogusThingyLoc

    {-# REWRITE_WITH_LOCATION someBogusThingy someBogusThingyLoc #-}

Now someBogusThingy behaves different depending on whether the call site
is on an even or uneven line number.  Admittedly, the example is
contrived, but I hope it illustrates the issue.

I do not insist on keeping it.  If we, as a community, decide, that we
do not need the IO here.  Then I'm fine with dropping it.


And FWIW, my vote *does* go towards dropping it. I put this proposal in the same category as rewrite rules in general: it's certainly possible for a bad implementation to wreak havoc, but it's the responsibility of the person using the rewrite rules to ensure that doesn't happen.

Michael