{-# options_ghc -Wno-orphans #-}
module Yaya.Unsafe.Fold.Instances where
import Control.Comonad.Cofree
import Control.Comonad.Env
import Control.Monad.Trans.Free
import Data.Functor.Classes
import Data.List.NonEmpty
import Yaya.Fold
import Yaya.Fold.Native
import Yaya.Pattern
import qualified Yaya.Unsafe.Fold as Unsafe
instance Functor f => Recursive (->) (Fix f) f where
cata = flip Unsafe.hylo project
instance (Functor f, Foldable f, Eq1 f) => Eq (Fix f) where
(==) = recursiveEq
instance (Functor f, Show1 f) => Show (Fix f) where
showsPrec = recursiveShowsPrec
instance Functor f => Corecursive (->) (Mu f) f where
ana = Unsafe.hylo embed
instance Functor f => Recursive (->) (Nu f) f where
cata = flip Unsafe.hylo project
instance (Functor f, Foldable f, Eq1 f) => Eq (Nu f) where
(==) = recursiveEq
instance (Functor f, Show1 f) => Show (Nu f) where
showsPrec = recursiveShowsPrec
instance Recursive (->) [a] (XNor a) where
cata = flip Unsafe.hylo project
instance Recursive (->) (NonEmpty a) (AndMaybe a) where
cata = flip Unsafe.hylo project
instance Functor f => Recursive (->) (Cofree f a) (EnvT a f) where
cata = flip Unsafe.hylo project
instance Functor f => Recursive (->) (Free f a) (FreeF f a) where
cata = flip Unsafe.hylo project
seqFreeT
:: (Functor f, Functor h)
=> DistributiveLaw (->) h f
-> DistributiveLaw (->) (Free h) f
seqFreeT k =
cata
(\case
Pure a -> free . Pure <$> a
Free ft -> free . Free <$> k ft)