Skip to content

Commit

Permalink
Introduce purs-tidy formatter (#25)
Browse files Browse the repository at this point in the history
* Add purs-tidy formatter

* Run purs-tidy
  • Loading branch information
thomashoneyman authored Nov 17, 2021
1 parent f102192 commit 32db796
Show file tree
Hide file tree
Showing 16 changed files with 493 additions and 471 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purs-tidy: "latest"

- name: Cache PureScript dependencies
uses: actions/cache@v2
Expand All @@ -32,3 +34,6 @@ jobs:

- name: Run tests
run: spago test --no-install

- name: Check formatting
run: purs-tidy check src test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!.gitignore
!.github
!.editorconfig
!.tidyrc.json

output
generated-docs
Expand Down
10 changes: 10 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"importSort": "source",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "never",
"width": null
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New features:
Bugfixes:

Other improvements:
- Added `purs-tidy` formatter (#25 by @thomashoneyman)
- Updated dependencies to clear build errors related to unlisted dependencies (#24 by @flounders)

## [v0.5.0](https://github.com/purescript-contrib/purescript-matryoshka/releases/tag/v0.5.0) - 2021-02-26
Expand Down
10 changes: 5 additions & 5 deletions src/Matryoshka/Algebra.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ limitations under the License.
module Matryoshka.Algebra where

type GAlgebra :: (Type -> Type) -> (Type -> Type) -> Type -> Type
type GAlgebra w f a = f (w a) a
type GAlgebra w f a = f (w a) -> a

type GAlgebraM :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) -> Type -> Type
type GAlgebraM w m f a = f (w a) m a
type GAlgebraM w m f a = f (w a) -> m a

type Algebra f a = f a a
type Algebra f a = f a -> a

type AlgebraM :: (Type -> Type) -> (Type -> Type) -> Type -> Type
type AlgebraM m f a = f a m a
type AlgebraM m f a = f a -> m a

type ElgotAlgebra :: (Type -> Type) -> (Type -> Type) -> Type -> Type
type ElgotAlgebra w f a = w (f a) a
type ElgotAlgebra w f a = w (f a) -> a
12 changes: 6 additions & 6 deletions src/Matryoshka/Class/Corecursive.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ import Data.Tuple (Tuple(..))

import Matryoshka.Pattern.CoEnvT (CoEnvT(..))

class Functor f Corecursive t f | t f where
embed f t t
class Functor f <= Corecursive t f | t -> f where
embed :: f t -> t

instance corecursiveMu Functor f Corecursive (Mu f) f where
instance corecursiveMu :: Functor f => Corecursive (Mu f) f where
embed = roll

instance corecursiveNu Functor f Corecursive (Nu f) f where
instance corecursiveNu :: Functor f => Corecursive (Nu f) f where
embed = flip unfold (map observe)

instance corecursiveFree Functor f Corecursive (Free f a) (CoEnvT a f) where
instance corecursiveFree :: Functor f => Corecursive (Free f a) (CoEnvT a f) where
embed (CoEnvT e) = either pure (join <<< liftF) e

instance corecursiveCofree Functor f Corecursive (Cofree f a) (EnvT a f) where
instance corecursiveCofree :: Functor f => Corecursive (Cofree f a) (EnvT a f) where
embed et = mkCofree (ask et) (lower et)
where
ask (EnvT (Tuple e _)) = e
Expand Down
12 changes: 6 additions & 6 deletions src/Matryoshka/Class/Recursive.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ import Data.Tuple (Tuple(..))

import Matryoshka.Pattern.CoEnvT (CoEnvT(..))

class Functor f Recursive t f | t f where
project t f t
class Functor f <= Recursive t f | t -> f where
project :: t -> f t

instance recursiveMu Functor f Recursive (Mu f) f where
instance recursiveMu :: Functor f => Recursive (Mu f) f where
project = unroll

instance recursiveNu Functor f Recursive (Nu f) f where
instance recursiveNu :: Functor f => Recursive (Nu f) f where
project = observe

instance recursiveFree Functor f Recursive (Free f a) (CoEnvT a f) where
instance recursiveFree :: Functor f => Recursive (Free f a) (CoEnvT a f) where
project = CoEnvT <<< either Right Left <<< resume

instance recursiveCofree Functor f Recursive (Cofree f a) (EnvT a f) where
instance recursiveCofree :: Functor f => Recursive (Cofree f a) (EnvT a f) where
project cf = EnvT $ Tuple (head cf) (tail cf)
10 changes: 5 additions & 5 deletions src/Matryoshka/Coalgebra.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ limitations under the License.
module Matryoshka.Coalgebra where

type GCoalgebra :: (Type -> Type) -> (Type -> Type) -> Type -> Type
type GCoalgebra n f a = a f (n a)
type GCoalgebra n f a = a -> f (n a)

type GCoalgebraM :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) -> Type -> Type
type GCoalgebraM n m f a = a m (f (n a))
type GCoalgebraM n m f a = a -> m (f (n a))

type Coalgebra f a = a f a
type Coalgebra f a = a -> f a

type CoalgebraM :: (Type -> Type) -> (Type -> Type) -> Type -> Type
type CoalgebraM m f a = a m (f a)
type CoalgebraM m f a = a -> m (f a)

type ElgotCoalgebra :: (Type -> Type) -> (Type -> Type) -> Type -> Type
type ElgotCoalgebra e f a = a e (f a)
type ElgotCoalgebra e f a = a -> e (f a)
80 changes: 40 additions & 40 deletions src/Matryoshka/DistributiveLaw.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,79 +37,79 @@ import Matryoshka.Class.Corecursive (class Corecursive, embed)
import Matryoshka.Class.Recursive (class Recursive, project)
import Matryoshka.Coalgebra (Coalgebra)

type DistributiveLaw f g = a. f (g a) g (f a)
type DistributiveLaw f g = forall a. f (g a) -> g (f a)

distApplicative f g. Traversable f Applicative g DistributiveLaw f g
distApplicative :: forall f g. Traversable f => Applicative g => DistributiveLaw f g
distApplicative = sequence

distDistributive f g. Traversable f Distributive g DistributiveLaw f g
distDistributive :: forall f g. Traversable f => Distributive g => DistributiveLaw f g
distDistributive = distribute

distCata f. Functor f DistributiveLaw f Identity
distCata :: forall f. Functor f => DistributiveLaw f Identity
distCata = wrap <<< map unwrap

distPara t f. Corecursive t f DistributiveLaw f (Tuple t)
distPara :: forall t f. Corecursive t f => DistributiveLaw f (Tuple t)
distPara = distZygo embed

distParaT
t f w
. Corecursive t f
Comonad w
DistributiveLaw f w
DistributiveLaw f (EnvT t w)
:: forall t f w
. Corecursive t f
=> Comonad w
=> DistributiveLaw f w
-> DistributiveLaw f (EnvT t w)
distParaT = distZygoT embed

distZygo f a. Functor f Algebra f a DistributiveLaw f (Tuple a)
distZygo :: forall f a. Functor f => Algebra f a -> DistributiveLaw f (Tuple a)
distZygo g m = Tuple (g (map fst m)) (map snd m)

distZygoT
f w a
. Functor f
Comonad w
Algebra f a
DistributiveLaw f w
DistributiveLaw f (EnvT a w)
:: forall f w a
. Functor f
=> Comonad w
=> Algebra f a
-> DistributiveLaw f w
-> DistributiveLaw f (EnvT a w)
distZygoT g k fe =
EnvT $ Tuple (g (fst <<< runEnvT <$> fe)) (k (lower <$> fe))

distHisto f. Functor f DistributiveLaw f (Cofree f)
distHisto :: forall f. Functor f => DistributiveLaw f (Cofree f)
distHisto = distGHisto identity

distGHisto
f h
. Functor f
Functor h
DistributiveLaw f h
DistributiveLaw f (Cofree h)
:: forall f h
. Functor f
=> Functor h
=> DistributiveLaw f h
-> DistributiveLaw f (Cofree h)
distGHisto k = unfoldCofree (map extract) (k <<< map tail)

distAna f. Functor f DistributiveLaw Identity f
distAna :: forall f. Functor f => DistributiveLaw Identity f
distAna = map wrap <<< unwrap

distApo t f. Recursive t f DistributiveLaw (Either t) f
distApo :: forall t f. Recursive t f => DistributiveLaw (Either t) f
distApo = distGApo project

distGApo f a. Functor f Coalgebra f a DistributiveLaw (Either a) f
distGApo :: forall f a. Functor f => Coalgebra f a -> DistributiveLaw (Either a) f
distGApo f = either (map Left <<< f) (map Right)

distGApoT
f m a
. Functor f
Functor m
Coalgebra f a
DistributiveLaw m f
DistributiveLaw (ExceptT a m) f
:: forall f m a
. Functor f
=> Functor m
=> Coalgebra f a
-> DistributiveLaw m f
-> DistributiveLaw (ExceptT a m) f
distGApoT g k = map ExceptT <<< k <<< map (distGApo g) <<< runExceptT

distFutu f. Functor f DistributiveLaw (Free f) f
distFutu :: forall f. Functor f => DistributiveLaw (Free f) f
distFutu = distGFutu identity

distGFutu
f h
. Functor f
Functor h
DistributiveLaw h f
DistributiveLaw (Free h) f
:: forall f h
. Functor f
=> Functor h
=> DistributiveLaw h f
-> DistributiveLaw (Free h) f
distGFutu k f = case resume f of
Left as join <<< liftF <$> k (distGFutu k <$> as)
Right b pure <$> b
Left as -> join <<< liftF <$> k (distGFutu k <$> as)
Right b -> pure <$> b
Loading

0 comments on commit 32db796

Please sign in to comment.