purescript-checked-exceptions icon indicating copy to clipboard operation
purescript-checked-exceptions copied to clipboard

throwing syntax sugar

Open reactormonk opened this issue 6 years ago • 2 comments

Also added a test.

reactormonk avatar Feb 20 '19 10:02 reactormonk

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.

natefaubion avatar Feb 28 '19 16:02 natefaubion

https://github.com/natefaubion/purescript-variant/pull/44

safareli avatar Oct 03 '19 18:10 safareli