{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# HLINT ignore "Unused LANGUAGE pragma" #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
module Grisette.Internal.Core.Data.Class.Solvable
  ( 
    Solvable (..),
    pattern Con,
    slocsym,
    ilocsym,
  )
where
import Data.String (IsString)
import qualified Data.Text as T
import Grisette.Internal.Core.Data.Class.AsKey (AsKey (AsKey), AsKey1 (AsKey1))
import Grisette.Internal.Core.Data.Symbol
  ( Identifier,
    Symbol (IndexedSymbol, SimpleSymbol),
    withLocation,
  )
import Language.Haskell.TH.Syntax.Compat (SpliceQ)
class (IsString t) => Solvable c t | t -> c where
  
  
  
  
  con :: c -> t
  
  
  
  
  
  
  
  conView :: t -> Maybe c
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  sym :: Symbol -> t
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  ssym :: Identifier -> t
  ssym = Symbol -> t
forall c t. Solvable c t => Symbol -> t
sym (Symbol -> t) -> (Identifier -> Symbol) -> Identifier -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> Symbol
SimpleSymbol
  
  
  
  
  
  
  
  isym :: Identifier -> Int -> t
  isym Identifier
nm Int
idx = Symbol -> t
forall c t. Solvable c t => Symbol -> t
sym (Symbol -> t) -> Symbol -> t
forall a b. (a -> b) -> a -> b
$ Identifier -> Int -> Symbol
IndexedSymbol Identifier
nm Int
idx
pattern Con :: (Solvable c t) => c -> t
pattern $mCon :: forall {r} {c} {t}.
Solvable c t =>
t -> (c -> r) -> ((# #) -> r) -> r
$bCon :: forall c t. Solvable c t => c -> t
Con c <-
  (conView -> Just c)
  where
    Con c
c = c -> t
forall c t. Solvable c t => c -> t
con c
c
slocsym :: (Solvable c s) => T.Text -> SpliceQ s
slocsym :: forall c s. Solvable c s => Text -> SpliceQ s
slocsym Text
nm = [||Identifier -> t
forall c t. Solvable c t => Identifier -> t
ssym $$(Text -> SpliceQ Identifier
withLocation Text
nm)||]
ilocsym :: (Solvable c s) => T.Text -> Int -> SpliceQ s
ilocsym :: forall c s. Solvable c s => Text -> Int -> SpliceQ s
ilocsym Text
nm Int
idx = [||Identifier -> Int -> t
forall c t. Solvable c t => Identifier -> Int -> t
isym $$(Text -> SpliceQ Identifier
withLocation Text
nm) Int
idx||]
instance (Solvable c s) => Solvable c (AsKey s) where
  con :: c -> AsKey s
con = s -> AsKey s
forall a. a -> AsKey a
AsKey (s -> AsKey s) -> (c -> s) -> c -> AsKey s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> s
forall c t. Solvable c t => c -> t
con
  conView :: AsKey s -> Maybe c
conView (AsKey s
s) = s -> Maybe c
forall c t. Solvable c t => t -> Maybe c
conView s
s
  sym :: Symbol -> AsKey s
sym = s -> AsKey s
forall a. a -> AsKey a
AsKey (s -> AsKey s) -> (Symbol -> s) -> Symbol -> AsKey s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Symbol -> s
forall c t. Solvable c t => Symbol -> t
sym
  ssym :: Identifier -> AsKey s
ssym = s -> AsKey s
forall a. a -> AsKey a
AsKey (s -> AsKey s) -> (Identifier -> s) -> Identifier -> AsKey s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> s
forall c t. Solvable c t => Identifier -> t
ssym
  isym :: Identifier -> Int -> AsKey s
isym Identifier
ident = s -> AsKey s
forall a. a -> AsKey a
AsKey (s -> AsKey s) -> (Int -> s) -> Int -> AsKey s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> Int -> s
forall c t. Solvable c t => Identifier -> Int -> t
isym Identifier
ident
instance (Solvable c (f s)) => Solvable c (AsKey1 f s) where
  con :: c -> AsKey1 f s
con = f s -> AsKey1 f s
forall (f :: * -> *) a. f a -> AsKey1 f a
AsKey1 (f s -> AsKey1 f s) -> (c -> f s) -> c -> AsKey1 f s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> f s
forall c t. Solvable c t => c -> t
con
  conView :: AsKey1 f s -> Maybe c
conView (AsKey1 f s
s) = f s -> Maybe c
forall c t. Solvable c t => t -> Maybe c
conView f s
s
  sym :: Symbol -> AsKey1 f s
sym = f s -> AsKey1 f s
forall (f :: * -> *) a. f a -> AsKey1 f a
AsKey1 (f s -> AsKey1 f s) -> (Symbol -> f s) -> Symbol -> AsKey1 f s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Symbol -> f s
forall c t. Solvable c t => Symbol -> t
sym
  ssym :: Identifier -> AsKey1 f s
ssym = f s -> AsKey1 f s
forall (f :: * -> *) a. f a -> AsKey1 f a
AsKey1 (f s -> AsKey1 f s)
-> (Identifier -> f s) -> Identifier -> AsKey1 f s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> f s
forall c t. Solvable c t => Identifier -> t
ssym
  isym :: Identifier -> Int -> AsKey1 f s
isym Identifier
ident = f s -> AsKey1 f s
forall (f :: * -> *) a. f a -> AsKey1 f a
AsKey1 (f s -> AsKey1 f s) -> (Int -> f s) -> Int -> AsKey1 f s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> Int -> f s
forall c t. Solvable c t => Identifier -> Int -> t
isym Identifier
ident