{-# LANGUAGE Safe #-}
{-# LANGUAGE NoStrictData #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
module Yaya.Fold.Native.Internal
( Cofix (Cofix, unCofix),
)
where
import "base" Control.Category (Category ((.)))
import "base" Data.Functor (Functor (fmap))
import "base" Data.Functor.Classes (Read1)
import "base" Text.Read (Read (readListPrec, readPrec), readListPrecDefault)
import "this" Yaya.Fold
( Corecursive (ana),
Projectable (project),
Steppable (embed),
steppableReadPrec,
)
data Cofix f = Cofix {forall (f :: * -> *). Cofix f -> f (Cofix f)
unCofix :: f (Cofix f)}
{-# HLINT ignore Cofix "Use newtype instead of data" #-}
instance Projectable (->) (Cofix f) f where
project :: Coalgebra (->) f (Cofix f)
project = Coalgebra (->) f (Cofix f)
forall (f :: * -> *). Cofix f -> f (Cofix f)
unCofix
instance Steppable (->) (Cofix f) f where
embed :: Algebra (->) f (Cofix f)
embed = Algebra (->) f (Cofix f)
forall (f :: * -> *). Algebra (->) f (Cofix f)
Cofix
instance (Functor f) => Corecursive (->) (Cofix f) f where
ana :: forall a. Coalgebra (->) f a -> a -> Cofix f
ana Coalgebra (->) f a
φ = Algebra (->) f (Cofix f)
forall {k} (c :: k -> k -> *) (t :: k) (f :: k -> k).
Steppable c t f =>
Algebra c f t
embed Algebra (->) f (Cofix f) -> (a -> f (Cofix f)) -> a -> Cofix f
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (a -> Cofix f) -> f a -> f (Cofix f)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Coalgebra (->) f a -> a -> Cofix f
forall a. Coalgebra (->) f a -> a -> Cofix f
forall {k} {k1} (c :: k -> k1 -> *) (t :: k1) (f :: k -> k1)
(a :: k).
Corecursive c t f =>
Coalgebra c f a -> c a t
ana Coalgebra (->) f a
φ) (f a -> f (Cofix f)) -> Coalgebra (->) f a -> a -> f (Cofix f)
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Coalgebra (->) f a
φ
instance (Read1 f) => Read (Cofix f) where
readPrec :: ReadPrec (Cofix f)
readPrec = ReadPrec (Cofix f)
forall t (f :: * -> *). (Steppable (->) t f, Read1 f) => ReadPrec t
steppableReadPrec
readListPrec :: ReadPrec [Cofix f]
readListPrec = ReadPrec [Cofix f]
forall a. Read a => ReadPrec [a]
readListPrecDefault