question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON/fold example in the README doesn't work

See original GitHub issue

Hi 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:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Gabriella439commented, Nov 23, 2022

Right. The idea is that a JSON value like this:

  [ true, 1, [ -2, false, "" ], null, { "foo": { } } ]

… is modeled as:

\constructors ->
    constructors.array
      [ constructors.bool true
      , constructors.natural 1
      , constructors.array [ constructors.integer -2, constructors.bool false, constructors.string "" ]
      , constructors.null
      , constructors.object [ { key = "foo", value = constructors.object [ ] } ]
      ]

… and the “handlers” that you’re passing to JSON/fold become the constructors argument to that function.

1reaction
Gabriella439commented, Nov 23, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found