From 6e5d4baa5f1929403a5009d39de06e183b4426fb Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 26 Jun 2019 08:41:25 -0400 Subject: [PATCH] Decompose sequences deeply. --- semantic-core/src/Data/Core.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/semantic-core/src/Data/Core.hs b/semantic-core/src/Data/Core.hs index 662f8ce77..a3272aa74 100644 --- a/semantic-core/src/Data/Core.hs +++ b/semantic-core/src/Data/Core.hs @@ -7,6 +7,7 @@ module Data.Core , lams , unlam , unseq +, unseqs , ($$*) , unapply , unapplies @@ -20,6 +21,7 @@ module Data.Core import Control.Applicative (Alternative (..)) import Control.Monad (ap) import Data.Foldable (foldl') +import Data.List.NonEmpty import Data.Loc import Data.Name import Data.Stack @@ -82,6 +84,12 @@ unseq :: Alternative m => Core a -> m (Core a, Core a) unseq (a :>> b) = pure (a, b) unseq _ = empty +unseqs :: Core a -> NonEmpty (Core a) +unseqs = go + where go t = case unseq t of + Just (l, r) -> go l <> go r + Nothing -> t :| [] + -- | Application of a function to a sequence of arguments. ($$*) :: Foldable t => Core a -> t (Core a) -> Core a ($$*) = foldl' (:$)