From bdc819cda86683183533e39ef3b4aff5399efc67 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Wed, 19 Jul 2023 14:41:01 -0700 Subject: [PATCH] address sequenceTuple issue --- .../Scenario/Topography/Navigation/Portal.hs | 20 ++++++++++++++++--- src/Swarm/Util.hs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Swarm/Game/Scenario/Topography/Navigation/Portal.hs b/src/Swarm/Game/Scenario/Topography/Navigation/Portal.hs index 143883d92f..d74e085367 100644 --- a/src/Swarm/Game/Scenario/Topography/Navigation/Portal.hs +++ b/src/Swarm/Game/Scenario/Topography/Navigation/Portal.hs @@ -257,22 +257,36 @@ ensureSpatialConsistency xs = nonUniform :: Map (SubworldName, SubworldName) (NonEmpty (V2 Int32)) nonUniform = M.filter ((not . allEqual) . NE.toList) vectorized --- | This signature looks a lot like the Traversable instance: +-- | +-- An implementation of 'sequenceA' for 'Signed' that does not +-- require an 'Applicative' instance for the inner 'Functor'. +-- +-- == Discussion +-- Compare to the 'Traversable' instance of 'Signed': -- @ -- instance Traversable Signed where -- traverse f (Positive x) = Positive <$> f x -- traverse f (Negative x) = Negative <$> f x -- @ -- --- if we were to substitute "id" for f: +-- if we were to substitute 'id' for f: -- @ -- traverse id (Positive x) = Positive <$> id x -- traverse id (Negative x) = Negative <$> id x -- @ +-- our implementation essentially becomes @traverse id@. +-- +-- However, we cannot simply write our implementation as @traverse id@, because +-- the 'traverse' function has an 'Applicative' constraint, which is superfluous +-- for our purpose. +-- +-- Perhaps there is an opportunity to invent a typeclass for datatypes which +-- consist exclusively of unary (or more ambitiously, non-nullary?) data constructors, +-- for which a less-constrained 'sequence' function could be automatically derived. sequenceSigned :: Functor f => Signed (f a) -> f (Signed a) sequenceSigned = \case Positive x -> Positive <$> x - Negative x -> Negative <$> x \ No newline at end of file + Negative x -> Negative <$> x diff --git a/src/Swarm/Util.hs b/src/Swarm/Util.hs index 07c1af4b0c..e71a8af8d5 100644 --- a/src/Swarm/Util.hs +++ b/src/Swarm/Util.hs @@ -22,7 +22,7 @@ module Swarm.Util ( findDup, both, allEqual, - + -- * Directory utilities readFileMay, readFileMayT,