PureScript on Production

The Backgound

API is Typed

type API = Kleisli[OptionT[F, ?], In[F], Out[F]]
to gain Type level safety
where In is Req and Out is Resp, F represent some effects which could be simply just IO

type API = Kleisli[OptionT[IO, ?], Req[IO], Resp[IO]]

if I read this loud it would be like our API is something that:
takes Req[IO] (which could has some IO happen, but not yet. i.e. there a json body)
returns Resp[IO] (which could end up with some IO ops as well)
but our API cannot handle all kind of request, some may end up with 404
so it’s OptionT[IO, Resp[IO] our API will finally got return

here is the Middleware type

Our Front-end is…


Well in TypeScript, the only thing you can model using Type is data

export interface Company {
  id: number
  companyId: CompanyId
  name: CompanyName
  account: CompanyAccount
  access: CompanyAccess
  country: string
  status: CompanyStatus
}

or little bit more than that: ADT
export type CompanyABN = ValidationError | ValidatedABN | EmptyABN

but in the end, we defined twice amount of LoC of such Type more than our actual Logic
most benifit is maybe

IDE works much better than JavaScript’s

and that twice amount of type could still end up run time error

let getCompany: Promise<Company> = getJSON<Company>("bank-end-url")

getJSON is actually from JS lib, so it won’t actually check the JSON response is actually able to parse into our Typed model

So what, is an strong Type System really that important?

Backend