From c746f937705e7859506b6658379e3a561f21fde3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 19 Mar 2024 14:45:20 -0400 Subject: [PATCH] Mendler-style recursion. --- semantic-analysis/src/Analysis/Syntax.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/semantic-analysis/src/Analysis/Syntax.hs b/semantic-analysis/src/Analysis/Syntax.hs index d2c4624aa2..2fb0112f90 100644 --- a/semantic-analysis/src/Analysis/Syntax.hs +++ b/semantic-analysis/src/Analysis/Syntax.hs @@ -1,10 +1,12 @@ {-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE RankNTypes #-} module Analysis.Syntax ( -- * Syntax Term(..) , subterms , foldTerm , paraTerm +, mendlerTerm ) where import qualified Data.Set as Set @@ -42,3 +44,9 @@ paraTerm var sig = go where go (Var v) = var v go (Term s) = sig ((,) <*> go <$> s) + +mendlerTerm :: (v -> r) -> (forall r' . (r' -> r) -> sig r'-> r) -> (Term sig v -> r) +mendlerTerm var sig = go + where + go (Var v) = var v + go (Term s) = sig go s