PureScript Foreign vs Argonaut
Until recently, it wasn't clear to me the "right way" to bring foreign data into PureScript.
For a while I was using purescript-foreign. I would get data from outside PureScript, and then use readString
, readInt
, readArray
, etc. to gradually build larger parsers to get an ADT (abstract data type). The paradigm seemed like read[type]
functions were being used as building blocks to larger data types.
That paradigm works to a certain extend, but the problem is purescript-foreign
doesn't seem to be intended for building larger types. It's meant to bridge the gap between native Javascript types and simple types in PureScript - that is Boolean
, Char
, String
, Number
, Int
, Array
, and native DOM elements. There's some discussion of this in a few purescript-foreign issues: #49, #30
Ultimately the big questions is, how do you get data outside PureScript into PureScript? This is my current understanding:
Are you just converting values between a javascript library and your app? Then use purescript-foreign.
Are the types more complicated and are they from an API? Then use purescript-argonaut or generics-rep. Use argonaut to manually encode/decode, and generic-rep to automatically do so.
Related Resources:
- Converting Data To and From Json in PureScript
- Automatically de/encoding JSON in Purescript using Generics-Rep