0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Advent of JustinAdvent Calendar 2018

Day 22

AOJ day 22: Naporitan, reflecting a record of proxies

Last updated at Posted at 2018-12-21

To group a bunch of proxies together either for convenience or for RowToList-directed type-level verification, you might choose to put them in a record. However, this usually leaves us in a position where we then need to go through and write out the value of our proxy literally, leading to a load of repetition and pain, where we need to make sure we have actually declared all of the fields in our record of proxy types below.

If PureScript has taught us anything, it's that if we have static knowledge about something, we should be able to derive its value.

"Reflecting a record of proxies and keys of row types"

In this post, I wrote about how we can once again use RowToList with the combination of Record.Builder to reflect a record of proxies into its value:

https://qiita.com/kimagure/items/b08175d22f9950ba3dfb

Just like that, we don't need to write any error-prone boilerplate, since we can use the compiler to derive the value:

proxies ::
  { apple :: Proxy Int
  , banana :: Proxy String
  }
proxies = N.reflectRecordProxy

I hope even if this example seems a bit silly, this really gives you some ideas on how powerful languages really can derive values for you from the types, and how this is really incredibly useful when you make a conscious choice of what you'd like to get out of your system. Otherwise, there would be a much smaller difference between PureScript and other languages.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?