purescript-prelude icon indicating copy to clipboard operation
purescript-prelude copied to clipboard

Kind-Polymorphism and `Show`

Open csicar opened this issue 4 years ago • 3 comments

As of 0.14, the Proxy-Zoo should get reduced to just one: Proxy. This means that creating type-class instances for proxied values is no longer possible (as far as I know)

For example in typelevel-peano (https://github.com/csicar/purescript-typelevel-peano/pull/4/files#diff-7de00383917fea851d52cc5de4f18f87329b6b3f4e2819a8ebcbf9d8c0d85a80R47) I had a Show-Instance for typelevel Ints, that would print the value representation:

>>> instance showNat :: Show (IProxy a) where show = reflectInt
>>> show (IProxy :: IProxy N10)
10

I think it would be nice to have the same functionality for Proxy as well:

-- In Type.Proxy
class KindShow a where
  kindShow :: Proxy a -> String

instance showkindShow :: (KindShow a) => Show (Proxy a) where
  show a = kindShow a

---- In client
data Int

reflectInt = ...

instance show :: KindShow Int where
  kindShow p = reflectInt p

Does that make sense? Is there an easier way?

csicar avatar Feb 20 '21 22:02 csicar

I feel like this would be better done outside of core to see how much usage it gets, and only bring it into core (if not contrib) once the design stabilizes and we agree that it should go here.

JordanMartinez avatar Dec 01 '21 03:12 JordanMartinez

That is understandable

I'm not sure if instance showKingShow can be defined outside of Type.Proxy, because it would be an orphan instance

csicar avatar Dec 03 '21 21:12 csicar

Ah, you're right.

Well, let me give a potentially better reason. We're currently discussing whether to even have Show in the first place (see #272). If we suddenly add it here for kinds, it feels like we're repeating history. Having a KindDebug would make more sense to me.

JordanMartinez avatar Dec 04 '21 02:12 JordanMartinez