Dhall-to-xml and xml-to-dhall prerelease


#1

https://git.sr.ht/~singpolyma/dhall-xml-ruby

This is pre-release and uses an unreleased (though will be out soon) version of the dhall gem. It also cannot be installed as described in the README yet but for now just clone the repo and run bundle install then you can use bundle exec ruby -Ilib/ bin/dhall-to-xml and so. The README describes how things will be when released as a gem (probably first release shortly after next dhall-ruby release after the soon-coming dhall-lang release).

$ echo 'https://github.com/dhall-lang/dhall-lang/raw/master/Prelude/XML/text "<&>"' | dhall-to-xml
&lt;&amp;&gt;

$ echo '<root><child id="1">hello</child></root>' | xml-to-dhall | dhall decode
  λ(_ : Type)
→ λ ( _
    : { element :
            { attributes :
                List { mapKey : Text, mapValue : Text }
            , content :
                List _
            , name :
                Text
            }
          → _@1
      , text :
          Text → _@1
      }
    )
→ _.element
  { attributes =
      [] : List { mapKey : Text, mapValue : Text }
  , content =
      [ _.element
        { attributes =
            [ { mapKey = "id", mapValue = "1" } ]
        , content =
            [ _.text "hello" ]
        , name =
            "child"
        }
      ]
  , name =
      "root"
  }

#2

Awesome! XML will be a really killer integration to add to the ecosystem :slight_smile:


#3

First release out: https://www.rubydoc.info/gems/dhall-xml/0.1.0


#4

Don’t forget to announce it via Twitter so I can retweet it from the dhall_lang account :slight_smile:

I can always create a tweet myself but I try to retweet when possible to give other contributors more visibility


#5

Amazing work @singpolyma, it is great to have a executable to make conversions but what about use as a library for other langs?
For some time i had the idea of make a haskell version of this and derive a java one with eta (and a js one with ghcjs?), do you think that something alike still makes sense?


#6

Not sure if @singpolyma implementation already supports it (or maybe it is planned) but i thought in a additional “semantic” conversion, similar to dhall-to-json, leveraging xml schema: a record would be a union, (disjoint) unions would be choices and so on.
I haven’t thought deeply about it but it seems you could encode dhall types as xml schemas and dhall values as xml “instances” of those schemas.

This way you could (optionally) convert a dhall expression in a pair of a xml schema and a xml document and the other way around.

EDIT: In fact, a subset of xml schema cause you can restrict the size of a list or the range of a number type (at least while dhall does’t have dependent types)


#7

For sure. We could do JVM with jruby, but more implementations hurts no one, especially if we coordinate on capability and there’s a legitimate use case (such as easier library ecosystem integration, like you say)


#8

Do you mean the tool would take an XML schema as input and try to fit the Dhall expression into that shape if reasonable? That might make sense… I’d have to brush up on schemas.