*Dhallish* is a ruby gem and provides an executable dhallish. This executable reads from *STDIN* and
*Dhallish* is a ruby gem and provides an executable dhallish. This executable reads from *STDIN* and
outputs *JSON*. The *JSON* output does not aim to be compatible with [dhall-to-json](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-json).
outputs *JSON*. The *JSON* output does not aim to be compatible with [dhall-to-json](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-json).
Install *Dhallish* by installing ruby and then typing `gem install dhallish` into your terminal.
*dhallish* accepts the following command line options
*dhallish* accepts the following command line options
-'--pretty': print prettified json
-`--pretty`: print prettified json
-'--type': print the type of the expression instead of its value
-`--type`: print the type of the expression instead of its value (in the current implementation, the input is still evaluated)
If passed a file as a command line argument, *dhallish* reads from that file instead of stdin.
If passed a file as a command line argument, *dhallish* reads from that file instead of stdin.
*Dhallish* can also be used from other ruby files, if './lib/dhallish.rb' is required from that file.
*Dhallish* can also be used from other ruby files, if `dhallish` is required from that file.
The following functions from './lib/dhalish.rb' can be used:
The following functions from `./lib/dhalish.rb` can be used:
-`dhallfile`: A string containing the path to a file that contains dhallish-code
-`dhallfile`: A string containing the path to a file that contains dhallish-code
-`basedir`: A string containing a path that is used when files are imported from a relative path
-`basedir`: A string containing a path that is used when files are imported from a relative path.
When nil is passed, the base directory of *dhallfile* is used.
-`Dhallish::empty_context(basedir=Dir.pwd)`
- Returns an empty context. *basedir* is used when files are imported from a relative path.
- In this context, only the dhall standard library and types will be defined.
-`Dhallish::define(ctx, name, value, type)`
- Define something of type `type` under the name `name` in `ctx`. Best look at an example below.
### Types:
The *evaluate* function described above returns ether a ruby value and its type or only the ruby value if an expected type is passed.
*Dhallish* represents the types `Natural`, `Integer` ,`Double`, `Bool` and `Text` simply as their ruby equivalents. `List` and `Record` are
represented as ruby lists and hashes. For functions/lambdas, types and unions there are special classes (have a look at `lib/types.rb`).
An `Optional` is represented ether as nil or as its actual value.
-`Dhallish::Types::{Natural, Integer, Double, Text, Bool}` can directly be passed as an expected type
-`Dhallish::Types::List.new(elmtype)` stands for a list with elements of type `elmtype`
-`Dhallish::Types::Optional.new(type)` stands for an optional which may contain something of type `type`
-`Dhallish::Types::Record.new({ "foo" => footype, "bar" => bartype })` stands for a record with the fields `foo` of type `footype` and `bar` or type `bartype`
-`Dhallish::Types::{TextList, NaturalList, IntegerList, DoubleList}` are predefined for convenience
### Examples:
```ruby
require'dhallish'
num,type=Dhallish::evaluate("42")
# num = 42
# type = Dhallish::Types::Natural
# Dhallish::create_ctx("???") and Dhallish::empty_ctx() are identical
ctx=Dhallish::create_ctx("
let f = \\(x: Natural) -> \\(y: Integer) -> Natural/toInteger x + y