TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Representing Heterogeneous Data

59 pointsby grep_itover 1 year ago

3 comments

elcritchover 1 year ago
&gt; This is a real trade-off. The feature I have here provides strictly less static safety than using sum types. There is a slight performance cost to checking the type tag when accessing case-specific fields. In return, you get simpler, more familiar syntax for working with case-specific fields, including mutable ones.<p>Interesting post! Nim uses variant&#x2F;case objects as well. Generally they&#x27;re pretty handy and more flexible than sum types as you can access non-variant fields as regular objects. Though it means you can&#x27;t use the same field name twice, however on the other hand you can bring common fields out of the case portion. Also, a single object can have multiple case variants which can be handy.<p>There&#x27;s a PR for adding the stricter sum types and pattern matching as well. <a href="https:&#x2F;&#x2F;github.com&#x2F;nim-lang&#x2F;RFCs&#x2F;issues&#x2F;525">https:&#x2F;&#x2F;github.com&#x2F;nim-lang&#x2F;RFCs&#x2F;issues&#x2F;525</a> Currently I just use a library for sum type syntax on top of object variants: <a href="https:&#x2F;&#x2F;github.com&#x2F;andreaferretti&#x2F;patty">https:&#x2F;&#x2F;github.com&#x2F;andreaferretti&#x2F;patty</a>
gavinrayover 1 year ago
For what it&#x27;s worth, the representation the author chose to go with is almost verbatim identical to how you declare variant object types in Nim.
skybrianover 1 year ago
A bit surprising that this shows up here even though Bob apparently hasn’t figured out a good answer yet. Maybe someone will know a good solution?
评论 #37725299 未加载
评论 #37725397 未加载