From b19a2daa1765e48ec5f02f56389da61ffd647323 Mon Sep 17 00:00:00 2001 From: Julien Moutinho <julm+symantic-base@sourcephile.fr> Date: Sun, 5 Sep 2021 19:51:09 +0200 Subject: [PATCH] iface: add class `SumFunctor` --- src/Symantic/Lang.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Symantic/Lang.hs b/src/Symantic/Lang.hs index 45fb31a..692ec72 100644 --- a/src/Symantic/Lang.hs +++ b/src/Symantic/Lang.hs @@ -175,11 +175,19 @@ class ProductFunctor repr where FromDerived2 ProductFunctor repr => repr a -> repr b -> repr (a, b) --- * Class 'AlternativeFunctor' -class AlternativeFunctor repr where - (<+>) :: repr a -> repr a -> repr a +-- * Class 'SumFunctor' +class SumFunctor repr where + (<+>) :: repr a -> repr b -> repr (Either a b) (<+>) = liftDerived2 (<+>) default (<+>) :: + FromDerived2 SumFunctor repr => + repr a -> repr b -> repr (Either a b) + +-- * Class 'AlternativeFunctor' +class AlternativeFunctor repr where + (<|>) :: repr a -> repr a -> repr a + (<|>) = liftDerived2 (<|>) + default (<|>) :: FromDerived2 AlternativeFunctor repr => repr a -> repr a -> repr a -- 2.47.0