Announcing `purescript-veither`: a `Variant` version of `Either`

I got an itch last Wednesday to try out an Either-less version of ExceptV from purescript-checked-exceptions that directly uses Variant the entire time rather than Either (Variant rows) a.

While fumbling around with that idea, I realized it would be easier to write if I had an underlying version of Variant that worked more like Either. Well, a few days of tinkering later, we now have purescript-veither, a Variant version of Either: https://github.com/JordanMartinez/purescript-veither

The Readme gives an idea for how it works. However, due to a bug with purs docs, you’ll have to read the docs in the source code and/or look at its tests to see it in action.

In terms of performance, I’m not sure how this data type compares to using Either (Variant rows) a due to the dictionary passing. But, it was fun to write.

7 Likes

Package set PR is pending, but I’ve finished porting ExceptT to VexceptT here:

Differences between ExceptV (what inspired this) and VexceptT are best summarized by their runtime representation comparison:

-- pure :: forall m a. Applicative m => a -> m a

-- Below examples remove the newtypes around them

-- Dropping the `Either` removes one layer of boxing at runtime...
pure (Left {type: "error", value: e})) :: ExceptV  (error :: e) m a
pure (     {type: "error", value: e})  :: VexceptT (error :: e) m a

-- ... but comes at the cost of this change. I'm not sure
-- if this results in a less performant 'happy path' computation.
pure (Right              a)) :: ExceptV  (error :: e) m a
pure ({type: "_", value: a}) :: VexceptT (error :: e) m a