Utilizing RowList metaprogramming for non-empty records?

47 views
Skip to first unread message

Adam Saleh

unread,
Oct 30, 2017, 4:41:39 AM10/30/17
to purescript
Hi all,

I have been playing around with the RowCons style meta-programming, mostly by downloading the purescript-map-record Justin Woo [1] and hacking away.
By reusing various parts of the library I managed to create fold [2], traverse [3] and even something that looks like sequence [4] if you squint hard enough.

What I think I am interested in now, is to create fold1, traverse1 and sequence1 equivalents.

My main motivation to create a proper sequence1 for records, where if I have some Apply m and i.e. {a : m x, b: m y} I can easily convert it to m {a : x, b: y}.
I don't think I would be able to manage a proper sequence with arbitrary Applicative m, because I don't think the compiler would be able to figure our the m for the empty record.

If I hard-code the Applicative though, as I did with Maybe in [4] it seems to work fine, so maybe there is some way?

Anyway, I understand that with the examples in purescript-map-record I am so far doing some-sort of type-level recursion that terminates with Nil row-list.
Is there a way to terminate one level higher? Or some other workaround?

I am using Pulp version 12.0.1, purs version 0.11.6 using node/v8.4.0

Thanks for any pointers!

Adam

[1] https://github.com/justinwoo/purescript-map-record
[2] https://github.com/AdamSaleh/purescript-map-record/blob/experiments/src/Main.purs#L14
[3] https://github.com/AdamSaleh/purescript-map-record/blob/experiments/src/Main.purs#L44
[4] https://github.com/AdamSaleh/purescript-map-record/blob/experiments/src/Main.purs#L98

Nathan Faubion

unread,
Nov 4, 2017, 1:59:50 PM11/4/17
to purescript
It would be possible with instance chains in 0.12, I think. The problem is you have two different `Cons` cases: one that attempts to match a tail of `Nil`, and then the alternative. This isn't possible in 0.11 without overlapping instances.
Reply all
Reply to author
Forward
0 new messages