Skip to content

Solve RowToList#2945

Merged
paf31 merged 1 commit intopurescript:masterfrom
LiamGoodacre:feature/row-labels
Jul 9, 2017
Merged

Solve RowToList#2945
paf31 merged 1 commit intopurescript:masterfrom
LiamGoodacre:feature/row-labels

Conversation

@LiamGoodacre
Copy link
Copy Markdown
Member

Will add a test once purescript/purescript-typelevel-prelude#11 is merged.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 16, 2017

Looks good! What do you think about including the types along with the labels?

@LiamGoodacre
Copy link
Copy Markdown
Member Author

Yeah, I'm not opposed. The two are equivalent in that we can use rowcons to look up the types. It'd probably be more convenient to have both though. In that case, what do you think about the names RowEntries/EntryList?

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 17, 2017

I was thinking RowToList originally. I'm hoping that we can build up a library of these sorts of classes: folds, maps, etc. once we have constraint kinds so that we can take a MPTC as an argument:

class RowMap f xs ys | f xs -> ys

instance auto1 :: RowMap f () ()
instance auto2 :: (f a b, RowMap f r1 r2) => RowMap f (l :: a | r1) (l :: b | r2)

@LiamGoodacre LiamGoodacre changed the title Solve RowLabels Solve RowToList Jun 17, 2017
@LiamGoodacre
Copy link
Copy Markdown
Member Author

LiamGoodacre commented Jun 17, 2017

Oh instead of two classes we can have the fundeps in both directions RowToList r l | r -> l, l -> r.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 18, 2017

With the new bidirectional fundep, what would the instances look like if you wrote them out? Does the coverage condition hold in both directions?

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 18, 2017

What I'm getting at is that a fundep doesn't just depend on the relation you're defining, but also how you define it, right? Like, numeric addition as a 3-way relation has the property that if you know two, you know the third, but in practice we define it by recursion on one or the other argument, so the coverage condition doesn't actually hold for one of the fundeps, I think.

@LiamGoodacre
Copy link
Copy Markdown
Member Author

Ah yeah, because RowList doesn't have the ordering invariant it means multiple RowLists can compute the same rows. So the bidirectional fundep doesn't make sense. Thanks!
I'll switch back to two classes when I get some time.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 18, 2017 via email

Copy link
Copy Markdown
Contributor

@paf31 paf31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Is it possible to add a test though?

@LiamGoodacre
Copy link
Copy Markdown
Member Author

Rebased on master. If I add a test now, it will either depend on my typelevel-prelude clone, or it will fail until we decide where to put the class.

@paf31 paf31 merged commit 0e2d820 into purescript:master Jul 9, 2017
@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jul 9, 2017

Thanks, looks great!

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jul 9, 2017

A little test I did in the REPL, for reference:

> data LProxy (list :: RowList) = LProxy
> :p
… f :: forall proxy row list. RowToList row list => proxy row -> LProxy list
… f _ = LProxy

> :t f { x: 1, y : 2}
LProxy (Cons "x" Int (Cons "y" Int Nil))

> -- testing open rows
> :t \o -> o.x (f o)
forall t4 t5 t8.            
  RowToList                 
    ( x :: LProxy t5 -> t8  
    | t4                    
    )                       
    t5                      
   => { x :: LProxy t5 -> t8
      | t4                  
      }                     
      -> t8

👍 Looks really great!

paf31 added a commit that referenced this pull request Jul 10, 2017
paf31 added a commit that referenced this pull request Jul 10, 2017
…2985)

* Revert "Fix child decl ordering (#2984)"

This reverts commit 7fdd39d.

* Revert "Only build master and semver tags in Travis (#2982)"

This reverts commit c41a7a4.

* Revert "Include comments in child declarations in HTML docs (#2981)"

This reverts commit ad6166f.

* Revert "Solve RowToList (#2945)"

This reverts commit 0e2d820.

* Revert "Fix links to type operators in HTML docs (#2979)"

This reverts commit 5fe26f2.

* Revert "Re-evaluate REPL globs during :reload (#2978)"

This reverts commit 50e1c68.

* Revert "[purs ide] Collect data constructors (#2976)"

This reverts commit c965f35.

* Revert "Replace synonyms in instance constraints (#2973)"

This reverts commit ee66e0d.

* Revert "Require single-method instance declarations to be indented (#2965)"

This reverts commit b3e470d.
@LiamGoodacre LiamGoodacre deleted the feature/row-labels branch May 9, 2021 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants