on 33c82fd help sign in
30 lines 903 B history raw
1module Data.Schematic.Path where
3import Data.Singletons
4import Data.Singletons.TypeLits
5import Data.Schematic.Utils
6import Data.Singletons.Prelude
7import Data.Text as T
10data PathSegment = Key Symbol | Ix Nat
12data instance Sing (jp :: PathSegment) where
13 SKey :: (KnownSymbol k, Known (Sing k)) => Sing (k :: Symbol) -> Sing (Key k)
14 SIx :: (KnownNat n, Known (Sing n)) => Sing (n :: Nat) -> Sing (Ix n)
16instance (KnownSymbol k, Known (Sing k))
17 => Known (Sing (Key k)) where
18 known = SKey known
20instance (KnownNat n, Known (Sing n))
21 => Known (Sing (Ix n)) where
22 known = SIx known
24pathToText :: Sing (ps :: [PathSegment]) -> Text
25pathToText = T.pack . go ""
26 where
27 go :: String -> Sing (ps :: [PathSegment]) -> String
28 go acc SNil = acc
29 go acc (SCons (SKey k) tl) = go (acc ++ "." ++ symbolVal k) tl
30 go acc (SCons (SIx n) tl) = go (acc ++ "[" ++ show (natVal n) ++ "]") tl