module Generics.Regular.Functions.Seq (
Seq(..), gdseq
) where
import Control.DeepSeq
import Generics.Regular.Base
class Seq f where
gseq :: (a -> b -> b) -> f a -> b -> b
instance Seq I where
gseq f (I x) = f x
instance (NFData a) => Seq (K a) where
gseq _ (K x) = deepseq x
instance Seq U where
gseq _ U = id
instance (Seq f, Seq g) => Seq (f :+: g) where
gseq f (L x) = gseq f x
gseq f (R y) = gseq f y
instance (Seq f, Seq g) => Seq (f :*: g) where
gseq f (x :*: y) = gseq f x . gseq f y
instance Seq f => Seq (C c f) where
gseq f (C x) = gseq f x
instance Seq f => Seq (S s f) where
gseq f (S x) = gseq f x
gdseq :: (Regular a, Seq (PF a)) => a -> b -> b
gdseq p = gseq gdseq (from p)