{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FunctionalDependencies #-}
module Generics.MRSOP.Base.Class where
import Data.Function (on)
import Generics.MRSOP.Base.Universe
import Generics.MRSOP.Util
class Family (ki :: kon -> *) (fam :: [*]) (codes :: [[[Atom kon]]])
| fam -> ki codes , ki codes -> fam
where
sfrom' :: SNat ix -> El fam ix -> Rep ki (El fam) (Lkup ix codes)
sto' :: SNat ix -> Rep ki (El fam) (Lkup ix codes) -> El fam ix
sfrom :: forall fam ki codes ix
. (Family ki fam codes)
=> El fam ix -> Rep ki (El fam) (Lkup ix codes)
sfrom el = sfrom' (getElSNat el) el
sto :: forall fam ki codes ix
. (Family ki fam codes , IsNat ix)
=> Rep ki (El fam) (Lkup ix codes) -> El fam ix
sto = sto' (getSNat' @ix)
dfrom :: forall ix ki fam codes
. (Family ki fam codes)
=> El fam ix
-> Fix ki codes ix
dfrom = Fix . mapRep dfrom . sfrom @fam
dto :: forall ix ki fam codes
. (Family ki fam codes , IsNat ix)
=> Rep ki (Fix ki codes) (Lkup ix codes)
-> El fam ix
dto = sto . mapRep (dto . unFix)
shallow :: forall fam ty ki codes ix
. (Family ki fam codes,
ix ~ Idx ty fam, Lkup ix fam ~ ty, IsNat ix)
=> ty -> Rep ki (El fam) (Lkup ix codes)
shallow = sfrom . into
deep :: forall fam ty ki codes ix
. (Family ki fam codes,
ix ~ Idx ty fam, Lkup ix fam ~ ty, IsNat ix)
=> ty -> Fix ki codes ix
deep = dfrom . into