Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make uppercase records in purescript?

I have an API that forces me to return a JSON in the form of

{ Field1: "something"
, Field2: 12 }

However, I have failed to model this in Purescript so far.

I understand that the purescript grammar sees the upper case field names and thinks it is the type of a field without a field name. So I it is not straight forward to just encode a function like

test :: Number -> { Field1 :: String, Field2 :: Number }

Without resorting to using external javascript functions to change the object into something else, is it at all possible to construct a record with upper case field names in purescript? And if so, how?

like image 311
Fabian Schneider Avatar asked Oct 28 '25 04:10

Fabian Schneider


1 Answers

Absolutely! PureScript allows any field names, not just "valid identifier" ones. You just have to double-quote them if they're weird:

x :: { "Field1" :: String, "Field2" :: String, "🍕" :: String }
x = { "Field1": "foo", "Field2": "bar", "🍕": "yum" }

y :: String
y = x."🍕"

Basically same deal as in JavaScript.

like image 160
Fyodor Soikin Avatar answered Oct 30 '25 05:10

Fyodor Soikin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!