Closed VizorKit closed 3 years ago
As users, we use PoolConfiguration
, but when this config needs to be passed to the underlying js library we don't want values of type Maybe
there.
Starting from the line linked below:
https://github.com/rightfold/purescript-postgresql-client/blob/680da31ee1c6430fe296788994fe029024c75ade/src/Database/PostgreSQL.purs#L84
is a function which performs this transformation from PoolConfiguration
to PoolConfiguration'
and then calls the FFI function ffiNewPool
Record of type PoolConfiguration'
is a valid object in javascript, because PureScript's records are just js objects with keys as labels.
But for example Maybe String
is not represented as a string or null
(feel free to call unsafeStringify
to see for yourself), whereas Nullable has this exact runtime representation that is suitable for FFI functions
Cool, thank you. This does make sense, maybe in more time I would see the reason as to why would we even use Maybe
over Nullable
in purescript. For now I can go with it. I'm sorry I chose this project to work with purescript and figure out the complex parts with Aff, Effect, FFI, etc. If you want me to go somewhere else I can.
Awesome :smile: You can check out the forum, here is the link to the specific thread with a repo you might be interested in https://discourse.purescript.org/t/purescript-ffi-best-practices/1081, and there's more if you search for 'FFI'. And there's more knowledge regarding Aff, Effect and FFI in PS on the internet, you can ask someone on slack
label:question Sorry, I'm new to purescript. I'm curious why we define 2 different models. It states that one is passed to the ffi. I transpiled each of these definitions to javascript, and only the first one exists. however, the first one appears to be a valid state to pass to the ffi method. Is there something in purescript that states we should do this, whats the reason?