purescript / purescript-prelude

The PureScript Prelude
BSD 3-Clause "New" or "Revised" License
163 stars 88 forks source link

Kind-Polymorphism and `Show` #260

Open csicar opened 3 years ago

csicar commented 3 years ago

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?

JordanMartinez commented 2 years ago

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.

csicar commented 2 years ago

That is understandable

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

JordanMartinez commented 2 years ago

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.