{-# language AllowAmbiguousTypes #-}
{-# language DataKinds #-}
{-# language FlexibleContexts #-}
{-# language FlexibleInstances #-}
{-# language MultiParamTypeClasses #-}
{-# language PolyKinds #-}
{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language TypeFamilies #-}
{-# language TypeOperators #-}
{-# language UndecidableInstances #-}
module Mu.Schema.Registry (
Registry, fromRegistry
, SLess.Term(..), SLess.Field(..), SLess.FieldValue(..)
) where
import Control.Applicative
import Data.Kind
import Data.Proxy
import GHC.TypeLits
import Mu.Schema.Class
import Mu.Schema.Definition
import qualified Mu.Schema.Interpretation.Schemaless as SLess
type Registry = Mappings Nat Schema'
fromRegistry :: forall r t. FromRegistry r t
=> SLess.Term -> Maybe t
fromRegistry :: Term -> Maybe t
fromRegistry = Proxy r -> Term -> Maybe t
forall (ms :: Registry) t.
FromRegistry ms t =>
Proxy ms -> Term -> Maybe t
fromRegistry' (Proxy r
forall k (t :: k). Proxy t
Proxy @r)
class FromRegistry (ms :: Registry) (t :: Type) where
fromRegistry' :: Proxy ms -> SLess.Term -> Maybe t
instance FromRegistry '[] t where
fromRegistry' :: Proxy '[] -> Term -> Maybe t
fromRegistry' Proxy '[]
_ Term
_ = Maybe t
forall a. Maybe a
Nothing
instance ( Traversable w, FromSchema s sty t
, SLess.CheckSchema s (s :/: sty), FromRegistry ms t )
=> FromRegistry ((n ':-> s) ': ms) t where
fromRegistry' :: Proxy ((n ':-> s) : ms) -> Term -> Maybe t
fromRegistry' Proxy ((n ':-> s) : ms)
_ Term
t = Term -> Maybe t
forall t1 f (sch :: Schema t1 f) t2 (sty :: t1).
(FromSchema sch sty t2, CheckSchema sch (sch :/: sty)) =>
Term -> Maybe t2
SLess.fromSchemalessTerm @s Term
t Maybe t -> Maybe t -> Maybe t
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Proxy ms -> Term -> Maybe t
forall (ms :: Registry) t.
FromRegistry ms t =>
Proxy ms -> Term -> Maybe t
fromRegistry' (Proxy ms
forall k (t :: k). Proxy t
Proxy @ms) Term
t