{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module Data.TypedEncoding.Common.Types.Validation where
import Data.Proxy
import GHC.TypeLits
import Data.TypedEncoding.Common.Types.Enc
import Data.TypedEncoding.Common.Types.Common
data Validation f (nm :: Symbol) (alg :: Symbol) conf str where
UnsafeMkValidation :: Proxy nm -> (forall (xs :: [Symbol]) . Enc (nm ': xs) conf str -> f (Enc xs conf str)) -> Validation f nm alg conf str
mkValidation :: forall f (nm :: Symbol) conf str . (forall (xs :: [Symbol]) . Enc (nm ': xs) conf str -> f (Enc xs conf str)) -> Validation f nm (AlgNm nm) conf str
mkValidation :: (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation f nm (AlgNm nm) conf str
mkValidation = Proxy @Symbol nm
-> (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation
f nm (Concat (LTakeUntil (ToList1 nm "") ":")) conf str
forall (nm :: Symbol) conf str (f :: * -> *) (alg :: Symbol).
Proxy @Symbol nm
-> (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation f nm alg conf str
UnsafeMkValidation Proxy @Symbol nm
forall k (t :: k). Proxy @k t
Proxy
{-# DEPRECATED mkValidation "Use _mkValidation" #-}
_mkValidation :: forall f (nm :: Symbol) conf str . (forall (xs :: [Symbol]) . Enc (nm ': xs) conf str -> f (Enc xs conf str)) -> Validation f nm (AlgNm nm) conf str
_mkValidation :: (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation f nm (AlgNm nm) conf str
_mkValidation = Proxy @Symbol nm
-> (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation
f nm (Concat (LTakeUntil (ToList1 nm "") ":")) conf str
forall (nm :: Symbol) conf str (f :: * -> *) (alg :: Symbol).
Proxy @Symbol nm
-> (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation f nm alg conf str
UnsafeMkValidation Proxy @Symbol nm
forall k (t :: k). Proxy @k t
Proxy
runValidation :: forall nm f xs conf str . Validation f nm nm conf str -> Enc (nm ': xs) conf str -> f (Enc xs conf str)
runValidation :: Validation f nm nm conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runValidation (UnsafeMkValidation Proxy @Symbol nm
_ forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
fn) = Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
fn
runValidation' :: forall alg nm f xs conf str . Validation f nm alg conf str -> Enc (nm ': xs) conf str -> f (Enc xs conf str)
runValidation' :: Validation f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runValidation' (UnsafeMkValidation Proxy @Symbol nm
_ forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
fn) = Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
fn
_runValidation :: forall nm f xs conf str alg . (AlgNm nm ~ alg) => Validation f nm alg conf str -> Enc (nm ': xs) conf str -> f (Enc xs conf str)
_runValidation :: Validation f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
_runValidation = forall (alg :: Symbol) (nm :: Symbol) (f :: * -> *)
(xs :: [Symbol]) conf str.
Validation f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
forall (nm :: Symbol) (f :: * -> *) (xs :: [Symbol]) conf str.
Validation f nm (AlgNm nm) conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runValidation' @(AlgNm nm)
data Validations f (nms :: [Symbol]) (algs :: [Symbol]) conf str where
ZeroV :: Validations f '[] '[] conf str
ConsV :: Validation f nm alg conf str -> Validations f nms algs conf str -> Validations f (nm ': nms) (alg ': algs) conf str
runValidationChecks' :: forall algs nms f c str . (Monad f) => Validations f nms algs c str -> Enc nms c str -> f (Enc ('[]::[Symbol]) c str)
runValidationChecks' :: Validations f nms algs c str
-> Enc @[Symbol] nms c str -> f (Enc @[Symbol] ('[] @Symbol) c str)
runValidationChecks' Validations f nms algs c str
ZeroV Enc @[Symbol] nms c str
enc0 = Enc @[Symbol] nms c str -> f (Enc @[Symbol] nms c str)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Enc @[Symbol] nms c str
enc0
runValidationChecks' (ConsV Validation f nm alg c str
fn Validations f nms algs c str
xs) Enc @[Symbol] nms c str
enc =
let f (Enc @[Symbol] nms c str)
re :: f (Enc _ c str) = Validation f nm alg c str
-> Enc @[Symbol] ((':) @Symbol nm nms) c str
-> f (Enc @[Symbol] nms c str)
forall (alg :: Symbol) (nm :: Symbol) (f :: * -> *)
(xs :: [Symbol]) conf str.
Validation f nm alg conf str
-> Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str)
runValidation' Validation f nm alg c str
fn Enc @[Symbol] nms c str
Enc @[Symbol] ((':) @Symbol nm nms) c str
enc
in f (Enc @[Symbol] nms c str)
re f (Enc @[Symbol] nms c str)
-> (Enc @[Symbol] nms c str
-> f (Enc @[Symbol] ('[] @Symbol) c str))
-> f (Enc @[Symbol] ('[] @Symbol) c str)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Validations f nms algs c str
-> Enc @[Symbol] nms c str -> f (Enc @[Symbol] ('[] @Symbol) c str)
forall (algs :: [Symbol]) (nms :: [Symbol]) (f :: * -> *) c str.
Monad f =>
Validations f nms algs c str
-> Enc @[Symbol] nms c str -> f (Enc @[Symbol] ('[] @Symbol) c str)
runValidationChecks' Validations f nms algs c str
xs