Skip to content

Commit

Permalink
Remove my unnecessary pattern functor for Cofree
Browse files Browse the repository at this point in the history
@ChrisPenner [pointed out that `free` already has
one](#5376 (review)).
  • Loading branch information
sellout committed Dec 11, 2024
1 parent 0fa62a4 commit bb5a56c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
12 changes: 5 additions & 7 deletions lib/unison-util-recursion/src/Unison/Util/Recursion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ module Unison.Util.Recursion
cataM,
para,
Fix (..),
Cofree' (..),
)
where

import Control.Arrow ((&&&))
import Control.Comonad.Cofree (Cofree ((:<)))
import Control.Comonad.Trans.Cofree (CofreeF)
import Control.Comonad.Trans.Cofree qualified as CofreeF
import Control.Monad ((<=<))

type Algebra f a = f a -> a
Expand Down Expand Up @@ -46,12 +47,9 @@ instance (Functor f) => Recursive (Fix f) f where
embed = Fix
project (Fix f) = f

data Cofree' f a x = a :<< f x
deriving (Foldable, Functor, Traversable)

-- |
--
-- __NB__: `Cofree` from “free” is lazy, so this instance is technically partial.
instance (Functor f) => Recursive (Cofree f a) (Cofree' f a) where
embed (a :<< fco) = a :< fco
project (a :< fco) = a :<< fco
instance (Functor f) => Recursive (Cofree f a) (CofreeF f a) where
embed (a CofreeF.:< fco) = a :< fco
project (a :< fco) = a CofreeF.:< fco
3 changes: 2 additions & 1 deletion parser-typechecker/src/Unison/Syntax/TermParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Unison.Syntax.TermParser
)
where

import Control.Comonad.Trans.Cofree (CofreeF ((:<)))
import Control.Monad.Reader (asks, local)
import Data.Bitraversable (bitraverse)
import Data.Char qualified as Char
Expand Down Expand Up @@ -607,7 +608,7 @@ doc2Block = do
let docAnn = Ann startDoc endDoc
(docAnn,) . docUntitledSection (gann docAnn) <$> traverse foldTop docContents
where
foldTop = cataM \(a :<< top) -> docTop a =<< bitraverse (cataM \(a :<< leaf) -> docLeaf a leaf) pure top
foldTop = cataM \(a :< top) -> docTop a =<< bitraverse (cataM \(a :< leaf) -> docLeaf a leaf) pure top

gann :: (Annotated a) => a -> Ann
gann = Ann.GeneratedFrom . ann
Expand Down
1 change: 1 addition & 0 deletions unison-syntax/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tests:
- base
- code-page
- easytest
- free
- megaparsec
- unison-core1
- unison-prelude
Expand Down
3 changes: 2 additions & 1 deletion unison-syntax/test/Unison/Test/Doc.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Unison.Test.Doc (test) where

import Control.Comonad.Trans.Cofree (CofreeF ((:<)))
import Data.Bifunctor (first)
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.Text (Text)
Expand Down Expand Up @@ -137,7 +138,7 @@ t s expected =
(crash . P.errorBundlePretty)
( \actual ->
let expected' = Doc.UntitledSection $ embed <$> expected
actual' = cata (\(_ :<< top) -> embed $ first (cata \(_ :<< leaf) -> embed leaf) top) <$> actual
actual' = cata (\(_ :< top) -> embed $ first (cata \(_ :< leaf) -> embed leaf) top) <$> actual
in if actual' == expected'
then ok
else do
Expand Down
1 change: 1 addition & 0 deletions unison-syntax/unison-syntax.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ test-suite syntax-tests
base
, code-page
, easytest
, free
, megaparsec
, text
, unison-core1
Expand Down

0 comments on commit bb5a56c

Please sign in to comment.