module Silkscreen.Nesting
(
NestingPrinter(..)
, incrNesting
, encloseNesting
, module Silkscreen
) where
import Silkscreen
class Printer p => NestingPrinter p where
askingNesting :: (Int -> p) -> p
localNesting :: (Int -> Int) -> p -> p
applyNesting :: p -> p
incrNesting :: NestingPrinter p => p -> p
incrNesting :: p -> p
incrNesting = (Int -> Int) -> p -> p
forall p. NestingPrinter p => (Int -> Int) -> p -> p
localNesting Int -> Int
forall a. Enum a => a -> a
succ
encloseNesting :: NestingPrinter p => p -> p -> p -> p
encloseNesting :: p -> p -> p -> p
encloseNesting p
l p
r = p -> p -> p -> p
forall p. Printer p => p -> p -> p -> p
enclose (p -> p
forall p. NestingPrinter p => p -> p
applyNesting p
l) (p -> p
forall p. NestingPrinter p => p -> p
applyNesting p
r) (p -> p) -> (p -> p) -> p -> p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p -> p
forall p. NestingPrinter p => p -> p
incrNesting
instance NestingPrinter b => NestingPrinter (a -> b) where
askingNesting :: (Int -> a -> b) -> a -> b
askingNesting Int -> a -> b
f = (Int -> b) -> b
forall p. NestingPrinter p => (Int -> p) -> p
askingNesting ((Int -> b) -> b) -> (a -> Int -> b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> a -> b) -> a -> Int -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> a -> b
f
localNesting :: (Int -> Int) -> (a -> b) -> a -> b
localNesting Int -> Int
f a -> b
p = (Int -> Int) -> b -> b
forall p. NestingPrinter p => (Int -> Int) -> p -> p
localNesting Int -> Int
f (b -> b) -> (a -> b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
p
applyNesting :: (a -> b) -> a -> b
applyNesting a -> b
p = b -> b
forall p. NestingPrinter p => p -> p
applyNesting (b -> b) -> (a -> b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
p