{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
module Examples.TypedEncoding.SomeEnc.SomeAnnotation where
import Data.TypedEncoding.Common.Types.Common
import Data.TypedEncoding.Common.Class.Common
import Data.TypedEncoding.Common.Util.TypeLits (withSomeSymbol, proxyCons)
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))