justinwoo / purescript-simple-json

A simple Purescript JSON library that uses types automatically
http://purescript-simple-json.readthedocs.io
MIT License
133 stars 45 forks source link

WriteForeign for functions #26

Closed jacereda closed 6 years ago

jacereda commented 6 years ago

Thoughts?

jacereda commented 6 years ago

I'll work later on this to extend it to Fn2 and friends. I think it could simplify some FFI code.

justinwoo commented 6 years ago

I don't get what this is for, why should we have this? Is there a function representation for this? I think you should newtype specific functions you want to use with WriteForeign if that comes up, this is a JSON library more than anything.

jacereda commented 6 years ago

Sometimes you want to pass a record to a JS library and one of the fields happens to be a callback. I think this can help in those cases.

jacereda commented 6 years ago

To avoid newtype boilerplate, I mean.

justinwoo commented 6 years ago

I think this shouldn't go in this library since it doesn't relate to JSON and it would give people invalid code that tries to stringify functions, which is something you never want

jacereda commented 6 years ago

I also feel this belongs in something like -foreign-generic, but AFAIK it lacks the records magic that makes this library so cool for interfacing to external JS libraries.

jacereda commented 6 years ago

As I see it, this library presents 2 different use cases, generating JSON and generating Foreign. I'm not thinking in the JSON part, but in the Foreign one.

justinwoo commented 6 years ago

It might work for a generic Foreign library since that doesn't promise anything other than working with Foreign, but I really would rather not deal with this here. If anything, the "WriteForeign" class has some implicit law about "only data that can be represented in JSON"

jacereda commented 6 years ago

Understood, closing.