README.md in qrb-0.2.0 vs README.md in qrb-0.3.0

- old
+ new

@@ -32,11 +32,11 @@ # And try dressing that data puts schema.dress(data) ``` -## About this Q binding +## ADTs with internal contracts Qrb tries to provide an idiomatic binding for ruby developers. In particular, it uses a simple convention-over-configuration protocol for information contracts. This protocol is easily described through an example. The following ADT definition: @@ -69,15 +69,44 @@ # ... end ``` +## ADTs with external contracts + +When the scenario above is not possible or not wanted (would require core +extensions for instance), Qrb allows defining ADTs with external contracts. +The following ADT definition: + +```ruby +Color = .Color <rgb> {r: Byte, g: Byte, b: Byte} ColorContract +``` + +expected the following ruby module: + +```ruby +module ColorContract + + def self.dress(tuple) + Color.new(tuple[:r], tuple[:g], tuple[:b]) + end + + def self.undress(color) + { r: color.r, g: color.g, b: color.b } + end + +end +``` + ## About representations The `Rep` representation function mapping Q types to ruby classes is as follows: ```ruby +# Any type is represented by Ruby's Object class +Rep(.) = Object + # Builtins are represented by the corresponding ruby class Rep(.Builtin) = Builtin # Sub types are represented by the same representation as the super type Rep(SuperType( s | ... )) = Rep(SuperType)