支持 sum 类型的高性能对象序列化库
I wonder if any of the high performance serialization libraries (like Google protocol buffers) support sum types.
Sum types are tagged unions, basically the ability to say that something is either A, B, or C. Sum types are used in languages such as Haskell and ML which support Algebraic Data Types
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果“像谷歌协议缓冲区”是指为多种语言生成代码的能力,那么这样的东西可能不存在。在不支持总和类型的语言中模拟总和类型充其量是很尴尬的(例如,尝试在 boost:variant 上进行模式匹配)。因此,如果主要目标是主流语言,则将它们排除在外是有意义的。
如果您满足于仅使用 haskell/ocaml/无论什么,都有很多选择。对于haskell,有cereal,binary、safecopy 以及其他可能。 ocaml 有 piqi 项目。
If by "like Google protocol buffers" you mean ability to generate code for multiple languages then probably such thing doesn't exist. Emulating sum types in languages which don't support them is awkward at best (try to pattern match on boost:variant for example). So it makes sense to leave them out if main target is mainstream languages.
If you are content with using only haskell/ocaml/whatever there is plenty of choices. For haskell there are cereal, binary, safecopy and probably others. There is piqi project for ocaml.
除了 Piqi (我是作者)之外,我不知道有任何支持求和类型的实用系统。 Piqi 与 Protocol Buffers 兼容,并且原生支持 OCaml 和 Erlang。 Protocol buffers 中缺少 sum 类型是我创建它的原因之一。
我的计划是扩展 Piqi 以支持其他语言,例如 Haskell、Clojure 等。
I'm not aware of any practical systems that support sum types other than Piqi (I'm the author). Piqi is compatible with Protocol Buffers and natively supports OCaml and Erlang. Absence of sum types in Protocol buffers was one of the reasons why I created it.
My plan is to expand Piqi to support other languages such as Haskell, Clojure, etc.
是否需要“高性能”格式?许多通用格式应该能够简单地使用现有的构造——具体来说,映射/哈希表,来支持联合(仅包含带有指示实际值类型的键的条目)。
因此,也许您可以只使用简单的约定来使用 JSON 等来传输此类内容。
Is there need for a "high-performance" format? Many general-purpose formats should be able to simply use existing constructs -- specifically, Maps/hashtables, to support unions (just include entry with key that indicates type of actual value).
So maybe you could just use simple convention to use, say, JSON, to transfer such content.