purescript / purescript-record

Functions for working with records and polymorphic labels
BSD 3-Clause "New" or "Revised" License
70 stars 31 forks source link

Show, Eq instances for Record type #11

Closed safareli closed 6 years ago

safareli commented 7 years ago

If I understand right, using RowList its now possible to define Show and Eq instance for Record type. Is there any plans to add these instances? Without Show instance for Record types its hard to use the repl. (from)

garyb commented 7 years ago

It'll probably happen, but it requires some reorganisation of the libraries - the instances for records will have to live with the class definitions to prevent them from being orphans (since record is a Prim type) - so for that to happen, -typelevel-prelude needs to be merged with or moved above -prelude in the dependency hierarchy.

paf31 commented 7 years ago

I think we should move the minimal amount of stuff needed to support this (i.e. RowList and classes) into Prelude as part of the 0.12.0 updates.

matthewleon commented 6 years ago

FWIW, in the meantime I've created this, which I find helpful: https://github.com/matthewleon/purescript-record-show

hdgarrood commented 6 years ago

Do you think it might be worth considering doing it before then? Just because all the stuff is already there and ready to go, it seems a shame to wait, and even after 0.12 is out I think it would be nice if people could take advantage of this without having to upgrade. Presumably this would only be a minor-level change for Prelude, and I don't think that would cause a huge amount of hassle since most people seem to be using caret (^) bounds for most dependencies..?

paf31 commented 6 years ago

We definitely could, especially since there is no plan for continued work on 0.12 right now anyway.

hdgarrood commented 6 years ago

Great! Looking at @matthewleon's record-show library, I guess that means the following would need to be moved above or into Prelude in the dependency hierarchy:

import Data.Record (get, delete)
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
import Type.Prelude (class RowToList, class RowLacks)
import Type.Row (kind RowList, Nil, Cons, RLProxy(..))

Does that seem doable? Or is there maybe a way of achieving this without using all of these?

hdgarrood commented 6 years ago

Come to think of it I suppose we could avoid the record dependency by cheating and using the FFI...? Also we could probably switch out delete for a version of unsafeCoerce which is specialised to have the same type, in order to avoid doing unnecessary work.

matthewleon commented 6 years ago

Come to think of it I suppose we could avoid the record dependency by cheating and using the FFI...?

Is there FFI use elsewhere in the Prelude?

hdgarrood commented 6 years ago

Yes; most of the Show instances need it, for example.

hdgarrood commented 6 years ago

On second thoughts, since we are moving some of these classes in 0.12, it's probably best to wait until 0.12. See https://github.com/purescript/purescript/issues/2903

garyb commented 6 years ago

These now exist in the 0.12 version of the prelude.