{-# LANGUAGE AllowAmbiguousTypes #-}

module Pandora.Paradigm.Structure.Ability.Focusable where

import Pandora.Pattern.Category ((.))
import Pandora.Pattern.Functor.Covariant (comap)
import Pandora.Pattern.Functor.Extractable (extract)
import Pandora.Paradigm.Inventory.Optics (type (:-.))
import Pandora.Paradigm.Primary.Functor.Tagged (Tagged (Tag))

class Focusable f t where
	type Focusing (f :: * -> k) (t :: * -> *) a
	focusing :: Tagged f (t a) :-. Focusing f t a

focus :: forall f t a . Focusable f t => t a :-. Focusing f t a
focus :: t a :-. Focusing f t a
focus = (Tagged f (t a) -> t a)
-> Store (Focusing f t a) (Tagged f (t a))
-> Store (Focusing f t a) (t a)
forall (t :: * -> *) a b. Covariant t => (a -> b) -> t a -> t b
comap Tagged f (t a) -> t a
forall (t :: * -> *) a. Extractable t => a <-| t
extract (Store (Focusing f t a) (Tagged f (t a))
 -> Store (Focusing f t a) (t a))
-> (t a -> Store (Focusing f t a) (Tagged f (t a)))
-> t a :-. Focusing f t a
forall (m :: * -> * -> *) b c a.
Category m =>
m b c -> m a b -> m a c
. Tagged f (t a) :-. Focusing f t a
forall k (f :: * -> k) (t :: * -> *) a.
Focusable f t =>
Tagged f (t a) :-. Focusing f t a
focusing (Tagged f (t a) :-. Focusing f t a)
-> (t a -> Tagged f (t a))
-> t a
-> Store (Focusing f t a) (Tagged f (t a))
forall (m :: * -> * -> *) b c a.
Category m =>
m b c -> m a b -> m a c
. forall a. a -> Tagged f a
forall k (tag :: k) a. a -> Tagged tag a
Tag @f

data Location a = Root a | Head a