argonaut Json and Foreign are the same thing?
eskimor opened this issue · 3 comments
Hi there!
Both Json and Foreign (from purescript-foreign) are simple untyped Javascript data? Is this correct?
If so, it would be nice to make them the same thing in purescript as well, e.g.:
type Json = Foreign
or the other way round. I am currently having the problem that I used the new shiny foreign-generic for serializing my data, but I want to use Affjax which expects a Json and not a Foreign, although they are the same.
I could of course use unsafeCoerce or some other dirty trick, but I really don't like that idea. What if argonaut for some reason changes it's representation some day?
Argonout would then need to depend on purescript-foreign. But is this a problem? It is tiny and this change would further establish purescript-foreign as gateway into the Javascript world, on which also argonaut can build upon.
Alternatively a function foreignToJson would also be ok. Doing unsafeCoerce behind the scenes. I can file a PR for one of those changes - if you want.
Thanks!
Ok, according to:
purescript-contrib/purescript-affjax#16
they are not the same thing. Don't really understand why though. (I am quite new to Javascript and Web development)
They are very similar, but they have slightly different purposes:
Foreignis supposed to be for safely converting from JavaScript values to PureScript. This isn't necessarily just JSON (purescript-domhas many conversions fromForeign), and is also why there is no instance forEither,Tuple, etc. as these types are not "from Javascript".- Argonaut is for JSON representations of any arbitrary data.
Thank you - closing :-)