on master help sign in
Add path
commit3b0f258dcfc3d04ca00f4c03c27ab6e47d843b9b authorDenis Redozubov <denis.redozubov@gmail.com> dateMon 22 May 2017, 17:24 (9 years ago) parent4972214
3 files changed+33
schematic.cabal+2 src/Data/Schematic/Path.hs+30 src/Data/Schematic/Schema.hs+1
schematic.cabal+2
@@ -18,7 +18,9 @@ cabal-version: >=1.10
1818library
1919 exposed-modules: Data.Schematic
2020 , Data.Schematic.Instances
21+ , Data.Schematic.Path
2122 , Data.Schematic.Schema
23+ , Data.Schematic.Validation
2224 , Data.Schematic.Utils
2325 -- ghc-options:
2426 -- other-modules:
src/Data/Schematic/Path.hsnew file+30
@@ -0,0 +1,30 @@
1+module Data.Schematic.Path where
2+
3+import Data.Singletons
4+import Data.Singletons.TypeLits
5+import Data.Schematic.Utils
6+import Data.Singletons.Prelude
7+import Data.Text as T
8+
9+
10+data PathSegment = Key Symbol | Ix Nat
11+
12+data 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)
15+
16+instance (KnownSymbol k, Known (Sing k))
17+ => Known (Sing (Key k)) where
18+ known = SKey known
19+
20+instance (KnownNat n, Known (Sing n))
21+ => Known (Sing (Ix n)) where
22+ known = SIx known
23+
24+pathToText :: Sing (ps :: [PathSegment]) -> Text
25+pathToText = 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
src/Data/Schematic/Schema.hs+1
@@ -8,6 +8,7 @@ module Data.Schematic.Schema where
88import Control.Applicative
99import Control.Category ((<<<), (>>>))
1010import Control.Monad
11+import Control.Monad.Validation
1112import Data.Aeson as J
1213import Data.Aeson.Types as J
1314import Data.Eq.Deriving (deriveEq1)