(Side note: I should have posted this in the Feedback category…)
Yesterday I’ve created and made the repository public of a FFI wrapper around the WebAssembly-related API (currently focused on Node’s one).
I’m fluent in Haskell, so learning PureScript wasn’t so hard. But this is my first project in PureScript. I got several questions when writing it:
Effect or pure for a mutable type’s constructor?
a (pure) or
Effect a (impure), especially when wrapping a mutable type’s constructor. For example
WebAssembly.Table is inherently mutable because it implements the
set method. So I marked it as impure. But its constructor doesn’t have any side-effects: it just creates a new
Table object. So I marked it as pure.
Is this a right way?
(2) Wrapping a new Error class
WebAssembly namespace provides several different error classes. So I want to make them distinct from the default
Error type. But the useful functions such as
try are currently only available for the
So I made a dirty hack where I typed
CompileError as just a record instead of a
foreign imported type and made a function to convert an
Error value into a
CompileError, to cheat the type checker:
I thought this has two advantages over defining a completely separate type from the default Error:
- The existing functions (e.g.
try) can be used for
CompileErrorwithout any change.
- If the
Errorwere defined as a record, the inheritance by
Errorwould be simulated thanks to row polymorphism (i.e.
.messageare available both in
CompileError.) So it’s extensible.
How do you think about that hack?