Purerl

The Purerl code is relatively easy to follow coming from any sort of JS environment, in essence it boils down to a single folder of code with a manifest describing the package and its dependencies. The compiler will take all of the Purescript and compile both it and the modules to the output directory and then it’s up to us to copy that to somewhere the Erlang compiler can find so it can be further compiled into the beam format.

It is convenient sometimes to share some code between the client and server, and in the demo_ps project this is located in a ‘./shared’ folder that is symlinked from ‘./server/shared’.

server/packages.dhall

This file contains a reference to a package set that is maintained by the Purerl Organisation. A package set is a collection of packages that (hopefully) work nicely together as well as a description of the dependencies between them.

1
2
let upstream =
      https://github.com/purerl/package-sets/releases/download/erl-0.14.3-20210709/packages.dhall sha256:9b07e1fe89050620e2ad7f7623d409f19b5e571f43c2bdb61242377f7b89d941

This is followed (presently) by some overrides of packages that exist within the package set, but of which we want later versions of (because we like to live life on the edge)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

let overrides =
  { erl-simplebus = upstream.erl-simplebus //
    { version = "52d374a8a7a0bb13db6a8ac6552c55e4e2da7d9f"
    }
  , erl-test-eunit = upstream.erl-test-eunit //
    { version = "ed31f51d19f1faba764c32bbad00fa7e4ef752d2"
    }
  , exceptions = upstream.exceptions //
    { version = "edef0014db73aa3136dd4ab2290becb29f6fe6c6"
    , repo = "https://github.com/robashton/purescript-exceptions/"
    }
  }
let additions =
      { erl-opentelemetry =
        { dependencies = [ "effect", "erl-lists", "erl-tuples" ]
        , repo = "https://github.com/id3as/purescript-erl-opentelemetry.git"
        , version = "f8842104a08e4d455084778f5e120347f4a28bd4"
        }
       , erl-binary =
        { dependencies = [ "prelude", "erl-lists" ]
        , repo = "https://github.com/id3as/purescript-erl-binary.git"
        , version = "423f1af8437670beab03463b3e9bc0a487f05ba4"
        }
      , erl-kernel =
        { dependencies =
          [ "convertable-options"
          , "datetime"
          , "effect"
          , "either"
          , "erl-atom"
          , "erl-binary"
          , "erl-lists"
          , "erl-process"
          , "erl-tuples"
          , "erl-untagged-union"
          , "foldable-traversable"
          , "foreign"
          , "functions"
          , "integers"
          , "maybe"
          , "newtype"
          , "partial"
          , "prelude"
          , "record"
          , "typelevel-prelude"
          , "unsafe-coerce"
          ]
        , repo = "https://github.com/id3as/purescript-erl-kernel.git"
        , version = "2c1f78a3aa6993e91e342a984c522b87b98bbb2b"
        }
      , erl-gun =
        { dependencies =
          [ "convertable-options"
          , "datetime"
          , "effect"
          , "either"
          , "erl-atom"
          , "erl-binary"
          , "erl-kernel"
          , "erl-lists"
          , "erl-maps"
          , "erl-process"
          , "erl-ssl"
          , "erl-tuples"
          , "erl-untagged-union"
          , "foreign"
          , "functions"
          , "maybe"
          , "prelude"
          , "record"
          , "simple-json"
          , "typelevel-prelude"
          ]
        , repo = "https://github.com/id3as/purescript-erl-gun.git"
        , version = "c25358f9bae80b9a2512a46f91f51438a7f621fc"
        }
      , erl-otp-types =
        { dependencies =
          [ "erl-atom"
          , "erl-binary"
          , "erl-kernel"
          , "foreign"
          , "prelude"
          , "unsafe-reference"
          ]
        , repo = "https://github.com/id3as/purescript-erl-otp-types.git"
        , version = "6470bc379447c406456e8ef1e6a79c80e3c5e8d1"
        }
      , erl-ranch =
        { dependencies =
          [ "convertable-options"
          , "effect"
          , "either"
          , "erl-atom"
          , "erl-kernel"
          , "erl-lists"
          , "erl-maps"
          , "erl-otp-types"
          , "erl-process"
          , "erl-ssl"
          , "erl-tuples"
          , "exceptions"
          , "foreign"
          , "maybe"
          , "prelude"
          , "record"
          , "typelevel-prelude"
          , "unsafe-coerce"
          ]
        , repo = "https://github.com/id3as/purescript-erl-ranch.git"
        , version = "08a76bd850ba00c3a120c1d149bed07f9fcc165d"
        }
      , erl-ssl =
        { dependencies =
          [ "convertable-options"
          , "datetime"
          , "effect"
          , "either"
          , "maybe"
          , "erl-atom"
          , "erl-binary"
          , "erl-lists"
          , "erl-kernel"
          , "erl-tuples"
          , "erl-logger"
          , "erl-otp-types"
          , "foreign"
          , "maybe"
          , "partial"
          , "prelude"
          , "record"
          , "unsafe-reference"
          ]
        , repo = "https://github.com/id3as/purescript-erl-ssl.git"
        , version = "2bd94ce343448406e579425e1b4140a6b6dd7de0"
        }
      , datetime-parsing =
        { dependencies = 
                [  "arrays"
                 , "datetime"
                 , "either"
                 , "enums"
                 , "foldable-traversable"
                 , "integers"
                 , "lists"
                 , "maybe"
                 , "numbers"
                 , "parsing"
                 , "prelude"
                 , "psci-support"
                 , "strings"  
                ]
        , repo = "https://github.com/flounders/purescript-datetime-parsing"
        , version = "10c0a9aecc60a2a5e8cff35bebe45be4dacaa7f8"
        }
      , sequences =
        { dependencies =
          [ "prelude"
          , "unsafe-coerce"
          , "partial"
          , "unfoldable"
          , "lazy"
          , "arrays"
          , "profunctor"
          , "maybe"
          , "tuples"
          , "newtype"
          ]
        , repo = "https://github.com/id3as/purescript-sequences.git"
        , version = "73fdb04afa32be8a3e3d1d37203592118d4307bc"
        }
      , convertable-options =
        { repo = "https://github.com/natefaubion/purescript-convertable-options"
        , dependencies = [ "effect", "maybe", "record" ]
        , version = "f20235d464e8767c469c3804cf6bec4501f970e6"
        }
      , erl-cowboy =
        { repo = "https://github.com/purerl/purescript-erl-cowboy.git"
        , dependencies =
          [ "console"
          , "effect"
          , "either"
          , "erl-atom"
          , "erl-binary"
          , "erl-kernel"
          , "erl-lists"
          , "erl-maps"
          , "erl-modules"
          , "erl-ranch"
          , "erl-tuples"
          , "foreign"
          , "functions"
          , "maybe"
          , "prelude"
          , "transformers"
          , "tuples"
          , "unsafe-coerce"
          ]
        , version = "ca4dd4a6432817fbe6ef9ab1814046f6827046cd"
        }
      , unsafe-reference =
        { repo = "https://github.com/purerl/purescript-unsafe-reference.git"
        , dependencies = [ "prelude"  ]
        , version = "464ee74d0c3ef50e7b661c13399697431f4b6251"
        }
      , erl-stetson =
        { repo = "https://github.com/id3as/purescript-erl-stetson.git"
        , dependencies =
          [ "erl-atom"
          , "erl-binary"
          , "erl-lists"
          , "erl-maps"
          , "erl-tuples"
          , "erl-modules"
          , "erl-cowboy"
          , "foreign"
          , "maybe"
          , "prelude"
          , "transformers"
          , "routing-duplex"
          ]
        , version = "a0c0bb4b5ad9046dd69c77197dc5dd025883ada2"
        }
      , erl-untagged-union =
        { dependencies =
          [ "erl-atom"
          , "erl-binary"
          , "erl-lists"
          , "erl-tuples"
          , "debug"
          , "foreign"
          , "typelevel-prelude"
          , "maybe"
          , "partial"
          , "prelude"
          , "unsafe-coerce"
          ]
        , repo = "https://github.com/id3as/purescript-erl-untagged-union.git"
        , version = "eb7a10c7930c4b99f1a6bfce767daa814d45dd2b"
        }
      , rationals =
        { repo = "https://github.com/anttih/purescript-rationals.git"
        , dependencies =
          [ "prelude"
          ]
        , version = "c883c972513380ae161d816ed42108acfe8cc8f6"
        }
      , erl-process =
        { repo = "https://github.com/id3as/purescript-erl-process.git"
        , dependencies =
          [ "console"
          , "prelude"
          , "effect"
          ]
        , version = "afbfa4e7a13c0d55609ff144d49982563fada7f5"
        }
      , erl-pinto =
        { repo = "https://github.com/id3as/purescript-erl-pinto.git"
        , dependencies =
          [ "erl-process"
          , "erl-lists"
          , "erl-atom"
          , "erl-kernel"
          , "datetime"
          , "erl-tuples"
          , "erl-modules"
          , "foreign"
          ]
        , version = "598587428b7b6711412312596f3825ea88d471d2"
        }
      , erl-nativerefs =
        { repo = "https://github.com/id3as/purescript-erl-nativerefs.git"
        , dependencies =
          [ "prelude"
          , "effect"
          , "erl-tuples"
          ]
        , version = "b90469380821615adf4cb58782ff246f79eec961"
        }
      , these =
        { repo = "https://github.com/purescript-contrib/purescript-these"
        , version = "a98d0a4e80c9a75fa359e1bcabb0230fb99c52fa"
        , dependencies =
          [ "prelude"
          , "quickcheck"
          , "quickcheck-laws"
          ]

        }
      , uri =
        { repo = "https://github.com/purescript-contrib/purescript-uri"
        , version = "041e717f0c5c663b787b532a00ac706e7897e932"
        , dependencies =
          [ "prelude"
          ]
        }
      , quickcheck =
        { repo = "https://github.com/id3as/purescript-quickcheck"
        , version = "694a781d4f441cfb264b9efa368a0441532133af"
        , dependencies =
          [ "prelude"
          , "lcg"
          ]
        }
      , quickcheck-laws =
        { repo = "https://github.com/purescript-contrib/purescript-quickcheck-laws"
        , version = "464597522e5e001adc2619676584871f423b9ea0"
        , dependencies =
          [ "prelude"
          ]
        }
      }

in  upstream // overrides // additions

This gives us an amount of flexibility to work on both a stable set of packages as well as actively developed/updated packages that we might ourselves be maintaining.

server/spago.dhall

Having set up the package set we want to refer to, we then define both the packages we’re interested in from that package set and where to look for the code files that we are going to write alongside all of this. We also specify that our backend is going to be ‘purerl’ because compiling all of this code into Javascript isn’t going to do us very much good.

{-
-}
{ name = "demo"
, dependencies =
  [ "console"
  , "control"
  , "datetime"
  , "effect"
  , "either"
  , "erl-atom"
  , "erl-binary"
  , "erl-cowboy"
  , "erl-lists"
  , "erl-logger"
  , "erl-maps"
  , "erl-modules"
  , "erl-pinto"
  , "erl-process"
  , "erl-simplebus"
  , "erl-stetson"
  , "erl-tuples"
  , "filterable"
  , "foldable-traversable"
  , "foreign"
  , "maybe"
  , "newtype"
  , "partial"
  , "prelude"
  , "psci-support"
  , "record"
  , "routing-duplex"
  , "simple-json"
  , "transformers"
  , "typelevel-prelude"
  , "unsafe-coerce"
  ]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
, backend = "purerl"
}

server/Makefile

Make is relatively well understood so while it’s not strictly necessary to have in in this project it’s nice to set up the build to be dependent on the files in the project so we don’t build unnecessarily. We could of course just invoke spago build from the ‘./rebar.config’ in top level and forgo this step.

server/src/*

All of the ‘.purs’ found within here (and nested directories) will be built by spago build and ‘.erl’ files will be produced the ‘output’ directory corresponding to those files.

These then get copied into ‘./src/compiled_ps’ for compilation by the standard Erlang workflow.