Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

purescript nested row polymorphism

Tags:

purescript

PureScript by Example 5.9 Exercise 1 and 2

My Solution:

type HasCity r s = { address :: { city :: String | r } | s }

livesInLA :: forall r s. HasCity r s -> Boolean
livesInLA { address: { city: "Los Angeles" } } = true
livesInLA _ = false

sameCity :: forall r s t u. HasCity r s -> HasCity t u -> Boolean
sameCity a b = a.address.city == b.address.city

Question:

forall r s t u. HasCity r s -> HasCity t u is nasty... Can it be simplified?

like image 685
topica Avatar asked Jan 22 '26 00:01

topica


1 Answers

If you want to preserve the rows as having optional fields, not really. The only slight simplification I can suggest would be:

forall r s. HasCity r s -> HasCity r s -> Boolean

But this would require that both arguments have exactly the same structure (while still allowing extra labels), whereas the original type only requires that each record has the fields used in the equality test.

like image 179
gb. Avatar answered Jan 27 '26 02:01

gb.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!