Proposal: k ~ l => IsLabel k (Proxy l)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Proposal: k ~ l => IsLabel k (Proxy l)

Fumiaki Kinoshita
I propose adding an IsLabel instance to Proxy where 

   fromLabel = Proxy

This is the only reasonable instance I can think of, and AFAIK there's no plan which would conflict [0].

The proposed instance allows us to explore API designs involving type-level strings with much less syntactic noise ( #foo is easier to type than @"foo"). I admit that the motivation is weak, but I think it's nice to have.


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: k ~ l => IsLabel k (Proxy l)

Eric Mertens
That instance seems fine to me.

It won't solve the general case of proxy arguments are those should typically be type variables rather than fixed Proxy type, so using an overloaded label would be ambiguous without a type signature:

example :: proxy a -> Int

So if you were designing an API intended to be used with an overloaded label it would probably make sense to pick a different type and just define the instance locally:

data StringProxy (str :: Symbol) = StringProxy; instance x ~ a => IsLabel x (StringProxy a) where fromLabel = StringProxy

since you were building an API intended to be used with overloaded labels. The user would find this less surprising as you'd be able to attach documentation to StringProxy explaining how it was intended to be used.

-Eric

On Tue, Jul 7, 2020 at 1:48 AM Fumiaki Kinoshita <[hidden email]> wrote:
I propose adding an IsLabel instance to Proxy where 

   fromLabel = Proxy

This is the only reasonable instance I can think of, and AFAIK there's no plan which would conflict [0].

The proposed instance allows us to explore API designs involving type-level strings with much less syntactic noise ( #foo is easier to type than @"foo"). I admit that the motivation is weak, but I think it's nice to have.

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


--
Eric Mertens

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries