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

Eric Mertens emertens at gmail.com
Tue Jul 7 15:07:13 UTC 2020


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 <fumiexcel at gmail.com>
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.
>
> [0]
> https://gitlab.haskell.org/ghc/ghc/-/wikis/records/overloaded-record-fields/magic-classes
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


-- 
Eric Mertens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200707/89686c03/attachment.html>


More information about the Libraries mailing list