type constructor section for (-> Bool), _not_ ((->) Bool)

I'm probably being dumb, but Hoogle nor the wiki are helping me. I want an instance and type improvement constraint of the form instance (f ~ (-> Bool)) => C Foo (f b) where ... The first arg to C is driving type improvement, for example: instance (f ~ []) => C Bar (f b) where ... (The real instances are more complex, and involve overlap, of course.) I'm trying to write a section to get the improved type (b -> Bool), but (-> Bool) or ((-> Bool) b) is invalid syntax. This is valid, but wrong: ((->) Bool) b -- gives (Bool -> b). I could do: data FlipFun b -- abstract instance (f ~ FlipFun) => C Foo (f b) where ... And a type function inside the class to generate the type. But then I'd have to apply the type function for all instances, and in most places it'd be id. ??

On Tue, Sep 03, 2013 at 11:33:46AM +0000, AntC wrote:
I'm probably being dumb, but Hoogle nor the wiki are helping me.
I want an instance and type improvement constraint of the form
instance (f ~ (-> Bool)) => C Foo (f b) where ...
The first arg to C is driving type improvement, for example:
instance (f ~ []) => C Bar (f b) where ...
(The real instances are more complex, and involve overlap, of course.)
I'm trying to write a section to get the improved type (b -> Bool), but (-> Bool) or ((-> Bool) b) is invalid syntax.
There is no operator section syntax for types. Moreover, this is not just an issue of syntax: it is impossible to partially apply a type constructor to anything other than its first argument, because there is no type-level lambda.
This is valid, but wrong: ((->) Bool) b -- gives (Bool -> b).
I could do:
data FlipFun b -- abstract instance (f ~ FlipFun) => C Foo (f b) where ...
And a type function inside the class to generate the type. But then I'd have to apply the type function for all instances, and in most places it'd be id.
That's the only way to do it that I know of. -Brent

Brent Yorgey
writes: On Tue, Sep 03, 2013 at 11:33:46AM +0000, AntC wrote:
I want an instance and type improvement constraint of the form
instance (f ~ (-> Bool)) => C Foo (f b) where ...
There is no operator section syntax for types. Moreover, this is not just an issue of syntax: it is impossible to partially apply a type constructor to anything other than its first argument, because there is no type-level lambda.
Thank you Brent, so I'm not being entirely dumb ;-).
data FlipFun b -- abstract instance (f ~ FlipFun) => C Foo (f b) where ...
And a type function inside the class to generate the type. But then I'd have to apply the type function for all instances, and in most places it'd be id.
That's the only way to do it that I know of.
OK, I've got that working. My class is a helper doing type discrimination. So the constraints have 'infected' the caller and the caller's caller, etc ... Elegant it ain't. AntC
participants (2)
-
AntC
-
Brent Yorgey