JSON/fold example in the README doesn't work
See original GitHub issueHi there 👋
When I attempt to paste the following snippet from the README into the Grace browser:
JSON/fold
{ "bool": \b -> if b then 1 else 0
, "natural": \x -> x
, "integer": Integer/abs
, "real": \_ -> 1
, "string": \_ -> 2
, "null": 3
, "object": List/length
, "array": \vs -> List/fold vs (\x -> \y -> x + y : Natural) 0
}
[ true, 1, [ -2, false, "" ], null, { foo: { } } ]
I get:
Not a subtype
The following type:
List a?
(input):1:1:
│
1 │ JSON/fold
│ ↑
… cannot be a subtype of:
{ cons: b? -> c? -> c?, nil: c? }
(input):9:21:
│
9 │ , "array": \vs -> List/fold vs (\x -> \y -> x + y : Natural) 0
│ ↑
I can’t understand how I might fix this given that Grace doesn’t support recursion, which seems like it’d be necessary in order to get the result that the README suggests: 10
. In fact I’m having trouble understanding the usefulness of JSON/fold
at all given that recursion isn’t supported…
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
django-jsonfield-compat/README.md at master - GitHub
This project is safe to use on Django 1.8 and up. If your combination of Django version and backend database doesn't support the...
Read more >django JSONField doesn't accept value - Stack Overflow
I want to create an instance of that model in admin panel but that JSONField returns a validation error (Enter a valid JSON.)...
Read more >Manual API Editor - ReadMe Documentation
Visit your page, and play around with the API Explorer. Every API is unique; let us know if something doesn't work and we'll...
Read more >A larave json field - Nova Packages
Maybe there exists a question about how this package works? I Should say that; this package doesn't have any corresponds component to the...
Read more >django-jsonfield - PyPI
Extras. jsonify templatetag. This allows you to convert a python data structure into JSON within a template: {% load jsonify %} <script> var...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right. The idea is that a JSON value like this:
… is modeled as:
… and the “handlers” that you’re passing to
JSON/fold
become theconstructors
argument to that function.Also, this blog post of mine might help for others who want to improve their intuition of how folds in general work:
https://www.haskellforall.com/2021/02/folds-are-constructor-substitution.html
There is also a useful Dhall-specific guide to recursion that is relevant, too (since Dhall has the same limitations as Grace):
https://docs.dhall-lang.org/howtos/How-to-translate-recursive-code-to-Dhall.html