[Haskell] Expecting more inlining for bit shifting
John Meacham
john at repetae.net
Mon Dec 4 23:08:32 EST 2006
On Wed, Oct 18, 2006 at 09:48:31AM +0100, Simon Peyton-Jones wrote:
> | I would think the easiest way to go about this would be to extend the
> | rules pragma.
> |
> | {-# RULES "shift/const-inline" forall x y# . shift x y# = ... #-}
> |
> | where variables ending in # will only match constants known at compile time
>
> Interesting idea. GHC can do that *internally* using a "BuiltinRule", and it's internal precisely because there's no obvious way to say "match only a literal".
>
> I suppose that you might also want to say "match only a constructor"? To have a rule for 'f' that would fire only when you saw
> f (Just x)
> or f Nothing
> but not f (g y)
>
> For that, a # would not really be appropriate.
>
>
> Would this be valuable? If so, think of a nice syntax. It's not trivial to implement, but not hard either.
heh. thinking of a nice syntax is what has kept me from exposing this
behavior to the user in jhc so far. :)
I am thinking something like the following:
{-# RULES "shift/const-inline" forall x y | is_constant y . shift x y = ... #-}
which uses '|' like in pattern matching, where it specifies a condition
the variable has to meet. so 'is_constant' will say whether y is
completely known at compile time.
the nice thing about this syntax is that it is extendable pretty easily
{-# RULES "foo/known" forall x y | is_whnf y . foo x y = ... #-}
where is_whnf will test whether y is bound directly to a constructor or
a lambda expression.
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Glasgow-haskell-users
mailing list