# Data Visualization Purescript Front-end
The front-end is written in PureScript; I renamed source files from *.purs to *.hs to get online syntax highlighting.
[PureScript](https://www.purescript.org/) is very similar to Haskell, but differs in several aspects. It is strict, and uses a somewhat different typeclass hierarchy. Notably
* `Effect` is equivalent to Haskell `IO`. For example, `console.log` has type `String -> Effect Unit` ([docs](https://pursuit.purescript.org/packages/purescript-console/4.4.0/docs/Effect.Console#v:log))
* `Aff` is an asynchronous effect monad. For example, an AJAX request would return `Aff (Either Error ResponseType)` ([docs](https://pursuit.purescript.org/packages/purescript-affjax/11.0.0/docs/Affjax#v:get)).
PureScript also heavily encourages writing total functions. For example, an [array indexing function](https://pursuit.purescript.org/packages/purescript-arrays/5.3.1/docs/Data.Array#v:(!!)) returns `Maybe a`. For partial indexing, one must use [`unsafeIndex`](https://pursuit.purescript.org/packages/purescript-arrays/5.3.1/docs/Data.Array#v:unsafeIndex) together with [`unsafePartial`](https://pursuit.purescript.org/packages/purescript-partial/2.0.1/docs/Partial.Unsafe#v:unsafePartial) - quite a bunch of loops to jump through. This repo doesn't use any partial functions.
Since this is a simple application, I didn't bother with any sort of effect management; everything effectful is in the `Effect` or `Aff` monad. If the application were to grow more, I would probably go for the "three-layered cake" architecture with a `ReaderT Env Effect` at the bottom.
Here are some interesting files:
* [Types.hs](https://nest.pijul.com/potocpav/frontend:main/A4YPCXNG44HRK.IUMAA) - Data types and their JSON deserialization
* [Api.hs](https://nest.pijul.com/potocpav/frontend:main/A4YPCXNG44HRK.R35AA) - GET request generation
* [Filtering.hs](https://nest.pijul.com/potocpav/frontend:main/A4YPCXNG44HRK.VWSQA) - Elm-like model-view-update component architecture. [Here is a screenshot](https://imgur.com/a/3YxVW9y).
* [Filter.hs](https://nest.pijul.com/potocpav/frontend:main/A4YPCXNG44HRK.YQ3QA) - A simple LL(0) parser combinator for trajectory filtering.