Generic-case: automatic case analysis with no boilerplate

This is cool. I am about to write such a generic deriving for PatternMatchable instances for eDSLs.

Fwiw, PatternMatchable looks like this (I posted an article here):

class PatternMatchable m k p c | m -> k, m p -> c, c -> m p where
  match :: ∀ b. k b => m p -> (c -> m b) -> m b
  be :: ∀ . c -> m p

The code you generated seems very close to match:

maybe :: forall a r. r -> (a -> r) -> Maybe a -> r
maybe = gcaseR @(Maybe a)
1 Like