1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Define a Syntax instance for sums.

This commit is contained in:
Rob Rix 2019-07-17 11:13:36 -04:00
parent f76f73cbeb
commit 7684e4c4cc
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -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)