From 7684e4c4ccd32891dcf502d739ecf5c8d75a8a04 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 17 Jul 2019 11:13:36 -0400 Subject: [PATCH] Define a Syntax instance for sums. --- semantic-core/src/Data/Term.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/semantic-core/src/Data/Term.hs b/semantic-core/src/Data/Term.hs index 61e0716fe..da7548f89 100644 --- a/semantic-core/src/Data/Term.hs +++ b/semantic-core/src/Data/Term.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveTraversable, FlexibleInstances, MultiParamTypeClasses, QuantifiedConstraints, RankNTypes, StandaloneDeriving, UndecidableInstances #-} +{-# LANGUAGE DeriveTraversable, FlexibleInstances, MultiParamTypeClasses, QuantifiedConstraints, RankNTypes, StandaloneDeriving, TypeOperators, UndecidableInstances #-} module Data.Term ( Term(..) , Syntax(..) @@ -54,3 +54,7 @@ class (HFunctor sig, forall g . Functor g => Functor (sig g)) => Syntax sig wher instance Syntax (Scope ()) where foldSyntax go bound free = Scope . go (bound . fmap (go free)) . unScope + +instance (Syntax l, Syntax r) => Syntax (l :+: r) where + foldSyntax go bound free (L l) = L (foldSyntax go bound free l) + foldSyntax go bound free (R r) = R (foldSyntax go bound free r)