purescript-checked-exceptions
purescript-checked-exceptions copied to clipboard
throwing syntax sugar
Also added a test.
I think this can be formulated without expand
:
class VariantInjTagged a b | a -> b where
injTagged :: Record a -> Variant b
instance variantInjTagged ::
( RowToList r1 (RL.Cons sym a RL.Nil)
, R.Cons sym a () r1
, R.Cons sym a rx r2
, IsSymbol sym
) =>
VariantInjTagged r1 r2 where
injTagged = inj (SProxy :: SProxy sym) <<< get (SProxy :: SProxy sym)
This would allow you to just write throw
as:
throw :: forall m r1 r2 a.
VariantInjTagged r1 r2 =>
MonadThrow (Variant r2) m =>
Record r1 ->
m a
throw = throwError <<< injTagged
I know I originally said that I didn't really want this sugar in Variant core, but I might reconsider. It does seem a but weird to stick this here.
https://github.com/natefaubion/purescript-variant/pull/44