High performance object serialization library supporting sum types
Asked Answered
M

3

8

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

Maculate answered 21/2, 2012 at 14:34 Comment(0)
E
2

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.

Enrichment answered 21/2, 2012 at 17:38 Comment(2)
Well you don't need pattern matching, only tagged unions. Another example would be a protobuf with 3 optional fields with a constraint that only one of them could be set at a time. I am mostly looking for cross platform with support for some mainstream language such as C++, Java, or maybe Python.Maculate
I think sum types are impractical (not imposible) without pattern matching. Use of optional fields is fragile since it's not possible to enforce that constaint generally. it's expected that you can concatenate messages and constraint may broken during concatenationEnrichment
V
2

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.

Vocable answered 21/2, 2012 at 18:12 Comment(0)
L
0

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.

Leatherwood answered 27/2, 2012 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.