Last active
August 29, 2015 14:15
-
-
Save drdozer/5b76df6534f2bae88d54 to your computer and use it in GitHub Desktop.
xsd built-in data types in scala - a sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait XsdSimpleTypes { | |
type anySimpleType | |
type string | |
type duration | |
type dateTime | |
type time | |
type date | |
type gYearMonth | |
type gYear | |
type gMonthDay | |
type gDay | |
type gMonth | |
type boolean | |
type base64Binary | |
type hexBinary | |
type float | |
type decimal | |
type double | |
type anyURI | |
type QName | |
type NOTATION | |
type normalizedString | |
type token | |
type language | |
type Name | |
type NMTOKEN | |
type NCName | |
type ID | |
type IDREF | |
type ENTITY | |
type IDREFS | |
type ENTITIES | |
type integer | |
type nonPositiveInteger | |
type long | |
type nonNegativeInteger | |
type negativeInteger | |
type int | |
type short | |
type byte | |
type unsignedLong | |
type positiveInteger | |
type unsignedInt | |
type unsignedShort | |
type unsignedByte | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait XsdSimpleTypesHiearachy[XSD <: XsdSimpleTypes] { | |
def derivedFrom_anySimpleType: XSD#anySimpleType >:~> Coproduct.` | |
XSD#string, | |
XSD#duration, | |
XSD#dateTime, | |
XSD#time, | |
XSD#date, | |
XSD#gYearMonth, | |
XSD#gYear, | |
XSD#gMonthDay, | |
XSD#gDay, | |
XSD#gMonth, | |
XSD#boolean, | |
XSD#base64Binary, | |
XSD#hexBinary, | |
XSD#float, | |
XSD#decimal, | |
XSD#double, | |
XSD#anyURI, | |
XSD#QName, | |
XSD#NOTATION`.T | |
def derivedFrom_string: | |
XSD#string >:~> XSD#normalizedString | |
def derivedFrom_normalizedString: | |
XSD#normalizedString >:~> XSD#token | |
def derivedFrom_token: | |
XSD#token >:~> Coproduct.`XSD#language, XSD#Name, XSD#NMTOKEN)`.T | |
def derivedFrom_Name: | |
XSD#Name >:~> XSD#NCName | |
def derivedFrom_NCName: | |
XSD#NCName >:~> Coproduct.`XSD#ID, XSD#IDREF, XSD#ENTITY`.T | |
def listOfIDREF: | |
XSD#IDREF >_*> XSD#IDREFS | |
def listOfENTITY: | |
XSD#ENTITY >_*> XSD#ENTITIES | |
def derivedFrom_decimal: | |
XSD#decimal >:~> XSD#integer | |
def derivedFrom_integer: | |
XSD#integer >:~> Coproduct.`XSD#nonPositiveInteger, XSD#long, XSD#nonNegativeInteger`.T | |
def derivedFrom_nonPositiveInteger: | |
XSD#nonPositiveInteger >:~> XSD#negativeInteger | |
def derivedFrom_long: | |
XSD#long >:~> XSD#int | |
def derivedFrom_int: | |
XSD#int >:~> XSD#short | |
def derivedFrom_short: | |
XSD#short >:~> XSD#byte | |
def derivedFrom_nonNegativeInteger: | |
XSD#nonNegativeInteger >:~> Coproduct.`XSD#unsignedLong, XSD#positiveInteger`.T | |
def derivedFrom_unsignedLong: | |
XSD#unsignedLong >:~> XSD#unsignedInt | |
def derivedFrom_unsignedInt: | |
XSD#unsignedInt >:~> XSD#unsignedShort | |
def derivedFrom_unsignedShort: | |
XSD#unsignedShort >:~> XSD#unsignedByte | |
} |
Notes:
The type T >_*> X
witnesses that X
is derived from T
as a list.
In the xsd serialized literal form, this will be values matching the serialized literal form of T
separated by whitespace. In the scala data space, this will most likely map down to some collection type. However, it may map down to tuples or even a case class, in situations were that makes sense.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes:
T >:~> X
witnesses thatT
has members that can be transformed naturally intoX
. This 'smells like' sub-typing.(T >:~> X)#sealed
witnesses that everyT
can be transformed naturally intoX
, as in a sealed type hierarchy.When
X
is a single type, it expresses that some instances ofT
can be viewed as instances ofX
. WhenX
is a coproduct likeCoproduct.```A, B```.T
, it witnesses that someX
can be viewed as instancesA
and some others asB
. This is not a covering axiom. That is, there may be instances ofT
that can't be expressed as anX
. For example,xsd#decimal >:~> xsd#integer
expresses that some decimals can be viewed as integers. However, some decimals have values outside the range of integers.Given
T >:~>X
, a natural fold can be derived, were there is a case for each type inX
and a fall-through of typeT
for values that could not be cast to any of the specific types. This makesT >:~> _
composable as a type-level monoid.(T >:~> X) |+| (T >:~> Y) ---> T >:~> (X |+| Y)
were ifX
andY
are both coproducts,X |+| Y
isCoproduct.ExtendBy
, and if either are not, they are lifted in as singleton coproducts first.