symbolVal can be mapped to type level lists. For this we need ScopedTypeVariables and PolyKinds in addition to DataKinds and TypeOperators .
{-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE PolyKinds #-} import Data.Proxy import GHC.TypeLits
We will define a class of types (of any type) for which we can "get the runtime value of type [String] ".
class SymbolVals a where symbolVals :: proxy a -> [String]
We can get a list of strings for any empty list of types.
instance SymbolVals '[] where symbolVals _ = []
We can get a list of strings for any type list, where we can get a string for the first type and a list of strings for the remainder.
instance (KnownSymbol h, SymbolVals t) => SymbolVals (h ': t) where symbolVals _ = symbolVal (Proxy :: Proxy h) : symbolVals (Proxy :: Proxy t)
source share