dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
919 stars 214 forks source link

Apply a function to a Dhall expression supplied via STDIN or file #2003

Open german1608 opened 4 years ago

german1608 commented 4 years ago

I have a large JSON list in a file, and I wanted to use json-to-dhall output to get the length using a oneliner without . Is there a subcommand in the dhall executable that receives a Dhall function as a flag, another Dhall expression via STDIN or file and outputs the result of applying the function to that expression?

An example could be more descriptive:

# A list with a lot of elements
$ cat sample.json
[ ... ]
$ json-to-dhall --file sample.json | dhall --apply "List/length"
1234
Gabriella439 commented 4 years ago

@german1608: There is not. The closest thing you can do is something like:

$ dhall "List/length SomeType $(json-to-dhall --file sample.json)"

Generally, the right solution to this problem is to provide language support for importing JSON into Dhall

trskop commented 4 years ago

@german1608, don't know if you're still interested, but use this a lot, but I have my own implementation dhall --aply from your example. With the implementation I'm using, your example would look like:

json-to-dhall --file sample.json | dhall-filter 'List/length input'

Where input : Input is parsed standard input exposed as two variables, one is the value (input) and the other is its type (Input). I wouldn't mind reimplementing it as part dhall-haskell, if there's wider interest.