Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Max Bolingbroke
2011/2/15 Gábor Lehel illiss...@gmail.com: This is a semi-related question I've been meaning to ask at some point: I suppose this also means it's not possible to write a class, write some rules for the class, and then have the rules be applied to every instance? (I.e. you'd have to write them

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Simon Peyton-Jones
...@haskell.org] On Behalf Of Max Bolingbroke | Sent: 15 February 2011 09:08 | To: Gábor Lehel | Cc: Haskell Cafe | Subject: Re: [Haskell-cafe] rewrite rules to specialize function according to | type class? | | 2011/2/15 Gábor Lehel illiss...@gmail.com: | This is a semi-related question I've been

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread José Pedro Magalhães
Hello, 2011/2/15 Simon Peyton-Jones simo...@microsoft.com but currently any pragmas in a class decl are treated as attaching to the *default method*, not to the method selector: Thanks for this clarification, I had wondered about this for a while. I think it would also be nice to mention

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Max Bolingbroke
2011/2/15 Simon Peyton-Jones simo...@microsoft.com: but currently any pragmas in a class decl are treated as attaching to the *default method*, not to the method selector: I see. I didn't realise that that was what was happening. Personally I find this a bit surprising, but I can see the

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Roman Leshchinskiy
Max Bolingbroke wrote: 2011/2/15 Simon Peyton-Jones simo...@microsoft.com: but currently any pragmas in a class decl are treated as attaching to the *default method*, not to the method selector: I see. I didn't realise that that was what was happening. Personally I find this a bit

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Max Bolingbroke
On 15 February 2011 11:23, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: I wouldn't necessarily expect this to guarantee inlining for the same reason that the following code doesn't guarantee that foo gets rewritten to big: foo = bar {-# INLINE bar #-} bar = big It might work with the

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Roman Leshchinskiy
Max Bolingbroke wrote: On 15 February 2011 11:23, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: I wouldn't necessarily expect this to guarantee inlining for the same reason that the following code doesn't guarantee that foo gets rewritten to big: foo = bar {-# INLINE bar #-} bar = big

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Max Bolingbroke
On 15 February 2011 15:12, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: Ah, but you assume that bar won't be inlined into foo first. Consider that it is perfectly acceptable for GHC to generate this: foo = big {-# INLINE bar #-} bar = big We did ask to inline bar, after all. Well, yes,

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Roman Leshchinskiy
Max Bolingbroke wrote: On 15 February 2011 15:12, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: Ah, but you assume that bar won't be inlined into foo first. Consider that it is perfectly acceptable for GHC to generate this: foo = big {-# INLINE bar #-} bar = big We did ask to inline bar,

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Max Bolingbroke
On 15 February 2011 16:45, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: Only if foo has an INLINE pragma. Otherwise, GHC uses whatever RHS is available when it wants to inline. Ah, I see! Well yes, in that case my workaround is indeed broken in the way you describe, and there is no way to

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-15 Thread Roman Leshchinskiy
Max Bolingbroke wrote: On 15 February 2011 16:45, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: Only if foo has an INLINE pragma. Otherwise, GHC uses whatever RHS is available when it wants to inline. Ah, I see! Well yes, in that case my workaround is indeed broken in the way you describe,

[Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-14 Thread Patrick Bahr
Hi all, I am trying to get a GHC rewrite rule that specialises a function according to the type of the argument of the function. Does anybody know whether it is possible to do that not with a concrete type but rather a type class? Consider the following example: class A a where toInt

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-14 Thread Max Bolingbroke
On 14 February 2011 21:43, Patrick Bahr pa...@arcor.de wrote: Am I doing something wrong or is it not possible for GHC to dispatch a rule according to type class constraints? As you have discovered this is not possible. You can write the rule for as many *particular* types as you like, but you

Re: [Haskell-cafe] rewrite rules to specialize function according to type class?

2011-02-14 Thread Gábor Lehel
On Tue, Feb 15, 2011 at 12:48 AM, Max Bolingbroke batterseapo...@hotmail.com wrote: On 14 February 2011 21:43, Patrick Bahr pa...@arcor.de wrote: Am I doing something wrong or is it not possible for GHC to dispatch a rule according to type class constraints? As you have discovered this is not