{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
module Data.TypedEncoding.Common.Types.SomeAnnotation where
import Data.TypedEncoding.Common.Types.Common
import Data.TypedEncoding.Common.Class.Util
import Data.TypedEncoding.Internal.Util
import Data.Proxy
import GHC.TypeLits
data SomeAnnotation where
MkSomeAnnotation :: SymbolList xs => Proxy xs -> SomeAnnotation
withSomeAnnotation :: SomeAnnotation -> (forall xs . SymbolList xs => Proxy xs -> r) -> r
withSomeAnnotation (MkSomeAnnotation p) fn = fn p
someAnnValue :: [EncAnn] -> SomeAnnotation
someAnnValue xs =
foldr (fn . someSymbolVal) (MkSomeAnnotation (Proxy :: Proxy '[])) xs
where
somesymbs = map someSymbolVal xs
fn ss (MkSomeAnnotation pxs) = withSomeSymbol ss (\px -> MkSomeAnnotation (px `proxyCons` pxs))
proxyCons :: forall (x :: Symbol) (xs :: [Symbol]) . Proxy x -> Proxy xs -> Proxy (x ': xs)
proxyCons _ _ = Proxy