Reputation: 319
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?
Upvotes: 3
Views: 170
Reputation: 4659
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.
Upvotes: 1