git.iko.soy/typeable/schematic
on master help sign in
Add path
3b0f258Denis Redozubov
schematic.cabal+2
@@ -18,7 +18,9 @@ cabal-version: >=1.10
18library
18library
19 exposed-modules: Data.Schematic
19 exposed-modules: Data.Schematic
20 , Data.Schematic.Instances
20 , Data.Schematic.Instances
21+ , Data.Schematic.Path
21 , Data.Schematic.Schema
22 , Data.Schematic.Schema
23+ , Data.Schematic.Validation
22 , Data.Schematic.Utils
24 , Data.Schematic.Utils
23 -- ghc-options:
25 -- ghc-options:
24 -- other-modules:
26 -- 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
8import Control.Applicative
8import Control.Applicative
9import Control.Category ((<<<), (>>>))
9import Control.Category ((<<<), (>>>))
10import Control.Monad
10import Control.Monad
11+import Control.Monad.Validation
11import Data.Aeson as J
12import Data.Aeson as J
12import Data.Aeson.Types as J
13import Data.Aeson.Types as J
13import Data.Eq.Deriving (deriveEq1)
14import Data.Eq.Deriving (deriveEq1)