-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Basic symantics for writing Embedded Domain-Specific Languages (EDSL). -- -- A collection of basic tagless-final combinators. @package symantic-base @version 0.0.2.20200708 -- | EOT (Either of Tuples) to/from ADT (Algebraic Data Type). to produce -- or consume custom ADT with (<:>) and -- (<+>). -- -- This is like what is done in generic-sop: -- https://hackage.haskell.org/package/generics-sop-0.5.1.0/docs/src/Generics.SOP.GGP.html#gSumFrom -- but using directly Either and Tuples instead of passing -- by the intermediary GADTs NP and NS. module Symantic.Base.ADT type family EoT (adt :: [[*]]) :: * -- | Return the type of snd-nested 2-tuples from the given list of -- types. type family Tuples (as :: [*]) :: (r :: *) -- | Normalized type-level representation of an Algebraic Data Type. type ADT (adt :: *) = ListOfRepSums (Rep adt) '[] -- | Collect the alternatives in a continuation passing-style. type family ListOfRepSums (a :: * -> *) (ss :: [[*]]) :: [[*]] -- | Collect the records in a continuation passing-style. type family ListOfRepProducts (a :: * -> *) (ps :: [*]) :: [*] type family TypeOfRepField (a :: * -> *) :: * type RepOfEoT a = RepOfEithers (Rep a) '[] -- | Morph the Either of Tuples corresponding to an -- ADT into a constructor of this ADT. This is the reverse -- of eotOfadt. adtOfeot :: Generic a => RepOfEoT a => EoT (ADT a) -> a class RepOfEithers (a :: * -> *) ss -- | Parse the Either (list-like) binary tree of EoT into the -- (:+:) (balanced) binary tree of Rep, using -- continuation passing-style for performance. repOfEithers :: RepOfEithers a ss => EoT (ListOfRepSums a ss) -> (a x -> r) -> (EoT ss -> r) -> r class RepOfTuples (a :: * -> *) (xs :: [*]) -- | Parse the Tuples (list-like) binary tree of EoT into the -- (:*:) (balanced) binary tree of Rep, using -- continuation passing-style for performance. repOfTuples :: RepOfTuples a xs => Tuples (ListOfRepProducts a xs) -> (a x -> Tuples xs -> r) -> r class RepOfField (a :: * -> *) repOfField :: RepOfField a => TypeOfRepField a -> a x type EoTOfRep a = EithersOfRep (Rep a) '[] -- | Morph the constructor of an ADT into the corresponding -- Either of Tuples of this ADT. This is the reverse -- of adtOfeot. eotOfadt :: Generic a => EoTOfRep a => a -> EoT (ADT a) class EithersOfRep (a :: * -> *) ss eithersOfRepL :: EithersOfRep a ss => a x -> EoT (ListOfRepSums a ss) eithersOfRepR :: EithersOfRep a ss => EoT ss -> EoT (ListOfRepSums a ss) class TuplesOfRep (a :: * -> *) (ps :: [*]) tuplesOfRep :: TuplesOfRep a ps => a x -> Tuples ps -> Tuples (ListOfRepProducts a ps) class FieldOfRep (a :: * -> *) fieldOfRep :: FieldOfRep a => a x -> TypeOfRepField a instance Symantic.Base.ADT.FieldOfRep a => Symantic.Base.ADT.TuplesOfRep (GHC.Generics.M1 GHC.Generics.S c a) (x : ps) instance Symantic.Base.ADT.FieldOfRep a => Symantic.Base.ADT.TuplesOfRep (GHC.Generics.M1 GHC.Generics.S c a) '[] instance Symantic.Base.ADT.FieldOfRep (GHC.Generics.K1 i a) instance Symantic.Base.ADT.TuplesOfRep a '[] => Symantic.Base.ADT.EithersOfRep (GHC.Generics.M1 GHC.Generics.C c a) '[] instance Symantic.Base.ADT.TuplesOfRep a '[] => Symantic.Base.ADT.EithersOfRep (GHC.Generics.M1 GHC.Generics.C c a) (ps : ss) instance (Symantic.Base.ADT.TuplesOfRep a (Symantic.Base.ADT.ListOfRepProducts b ps), Symantic.Base.ADT.TuplesOfRep b ps) => Symantic.Base.ADT.TuplesOfRep (a GHC.Generics.:*: b) ps instance Symantic.Base.ADT.TuplesOfRep GHC.Generics.U1 ps instance (Symantic.Base.ADT.EithersOfRep a (Symantic.Base.ADT.ListOfRepSums b ss), Symantic.Base.ADT.EithersOfRep b ss) => Symantic.Base.ADT.EithersOfRep (a GHC.Generics.:+: b) ss instance Symantic.Base.ADT.EithersOfRep a ss => Symantic.Base.ADT.EithersOfRep (GHC.Generics.M1 GHC.Generics.D c a) ss instance Symantic.Base.ADT.EithersOfRep GHC.Generics.V1 ss instance Symantic.Base.ADT.RepOfField a => Symantic.Base.ADT.RepOfTuples (GHC.Generics.M1 GHC.Generics.S c a) (p : ps) instance Symantic.Base.ADT.RepOfField a => Symantic.Base.ADT.RepOfTuples (GHC.Generics.M1 GHC.Generics.S c a) '[] instance Symantic.Base.ADT.RepOfField (GHC.Generics.K1 i a) instance Symantic.Base.ADT.RepOfTuples a '[] => Symantic.Base.ADT.RepOfEithers (GHC.Generics.M1 GHC.Generics.C c a) (ps : ss) instance Symantic.Base.ADT.RepOfTuples a '[] => Symantic.Base.ADT.RepOfEithers (GHC.Generics.M1 GHC.Generics.C c a) '[] instance (Symantic.Base.ADT.RepOfTuples a (Symantic.Base.ADT.ListOfRepProducts b ps), Symantic.Base.ADT.RepOfTuples b ps) => Symantic.Base.ADT.RepOfTuples (a GHC.Generics.:*: b) ps instance Symantic.Base.ADT.RepOfTuples GHC.Generics.U1 ps instance (Symantic.Base.ADT.RepOfEithers a (Symantic.Base.ADT.ListOfRepSums b ss), Symantic.Base.ADT.RepOfEithers b ss) => Symantic.Base.ADT.RepOfEithers (a GHC.Generics.:+: b) ss instance Symantic.Base.ADT.RepOfEithers a ss => Symantic.Base.ADT.RepOfEithers (GHC.Generics.M1 GHC.Generics.D c a) ss instance Symantic.Base.ADT.RepOfEithers GHC.Generics.V1 ss module Symantic.Base.Composable class Composable repr (<.>) :: (Composable repr, Transformable repr) => Composable (UnTrans repr) => repr a b -> repr b c -> repr a c (<.>) :: Composable repr => repr a b -> repr b c -> repr a c infixr 4 <.> class Voidable repr void :: (Voidable repr, Transformable repr) => Voidable (UnTrans repr) => a -> repr (a -> b) k -> repr b k void :: Voidable repr => a -> repr (a -> b) k -> repr b k -- | Used with DefaultSignatures and default methods, in the -- symantics class definition, it then avoids on an interpreter instance -- to define unused methods. class Transformable repr where { -- | The underlying representation that (repr) transforms. type family UnTrans repr :: * -> * -> *; } -- | Lift the underlying representation to (repr). Useful to -- define a combinator that does nothing in a transformation. noTrans :: Transformable repr => UnTrans repr a b -> repr a b -- | Unlift a representation. Useful when a transformation combinator needs -- to access the UnTransformed representation, or at the end to -- get the underlying UnTransformed representation from the -- inferred (repr) value. unTrans :: Transformable repr => repr a b -> UnTrans repr a b -- | Convenient helper lifing an unary operator, but also enables to -- identify unary operators. trans1 :: Transformable repr => (UnTrans repr a b -> UnTrans repr c d) -> repr a b -> repr c d -- | Convenient helper lifting a binary operator, but also enables to -- identify binary operators. trans2 :: Transformable repr => (UnTrans repr a b -> UnTrans repr c d -> UnTrans repr e f) -> repr a b -> repr c d -> repr e f -- | A Transformable that does nothing. newtype IdentityTrans repr a k IdentityTrans :: repr a k -> IdentityTrans repr a k [unIdentityTrans] :: IdentityTrans repr a k -> repr a k class Dimapable repr dimap :: (Dimapable repr, Transformable repr) => Dimapable (UnTrans repr) => (a -> b) -> (b -> a) -> repr (a -> k) k -> repr (b -> k) k dimap :: Dimapable repr => (a -> b) -> (b -> a) -> repr (a -> k) k -> repr (b -> k) k instance Symantic.Base.Composable.Transformable (Symantic.Base.Composable.IdentityTrans repr) module Symantic.Base.CurryN -- | Produce and consume Tuples. Not actually useful for the Generic -- side of this module, but related through the use of Tuples. class CurryN args curryN :: CurryN args => (Tuples args -> res) -> args -..-> res uncurryN :: CurryN args => (args -..-> res) -> Tuples args -> res mapresultN :: CurryN args => (a -> b) -> (args -..-> a) -> args -..-> b type family (args :: [*]) -..-> (r :: *) :: * type family Args (f :: *) :: [*] type family Result (as :: *) :: * instance Symantic.Base.CurryN.CurryN '[a] instance Symantic.Base.CurryN.CurryN (b : as) => Symantic.Base.CurryN.CurryN (a : b : as) module Symantic.Base.Algebrable -- | (adt SomeADT some_expr) wrap/unwrap -- (some_expr) input/output value to/from the Algebraic Data -- Type (SomeADT). (SomeADT) must have a Generic -- instance (using the DeriveGeneric language extension to GHC). adt :: forall adt repr k. Dimapable repr => Generic adt => RepOfEoT adt => EoTOfRep adt => repr (EoT (ADT adt) -> k) k -> repr (adt -> k) k class Tupable repr (<:>) :: (Tupable repr, Transformable repr) => Tupable (UnTrans repr) => repr (a -> k) k -> repr (b -> k) k -> repr ((a, b) -> k) k (<:>) :: Tupable repr => repr (a -> k) k -> repr (b -> k) k -> repr ((a, b) -> k) k infixr 4 <:> class Unitable repr unit :: (Unitable repr, Transformable repr) => Unitable (UnTrans repr) => repr (() -> k) k unit :: Unitable repr => repr (() -> k) k class Constant repr constant :: (Constant repr, Transformable repr) => Constant (UnTrans repr) => a -> repr (a -> k) k constant :: Constant repr => a -> repr (a -> k) k class Eitherable repr (<+>) :: (Eitherable repr, Transformable repr) => Eitherable (UnTrans repr) => repr (a -> k) k -> repr (b -> k) k -> repr (Either a b -> k) k (<+>) :: Eitherable repr => repr (a -> k) k -> repr (b -> k) k -> repr (Either a b -> k) k infixr 3 <+> class Emptyable repr empty :: (Emptyable repr, Transformable repr) => Emptyable (UnTrans repr) => repr k k empty :: Emptyable repr => repr k k class Optionable repr option :: (Optionable repr, Transformable repr) => Optionable (UnTrans repr) => repr k k -> repr k k option :: Optionable repr => repr k k -> repr k k optional :: (Optionable repr, Transformable repr) => Optionable (UnTrans repr) => repr (a -> k) k -> repr (Maybe a -> k) k optional :: Optionable repr => repr (a -> k) k -> repr (Maybe a -> k) k class Repeatable repr many0 :: (Repeatable repr, Transformable repr) => Repeatable (UnTrans repr) => repr (a -> k) k -> repr ([a] -> k) k many0 :: Repeatable repr => repr (a -> k) k -> repr ([a] -> k) k many1 :: (Repeatable repr, Transformable repr) => Repeatable (UnTrans repr) => repr (a -> k) k -> repr ([a] -> k) k many1 :: Repeatable repr => repr (a -> k) k -> repr ([a] -> k) k class Substractable repr (<->) :: (Substractable repr, Transformable repr) => Substractable (UnTrans repr) => repr a k -> repr k' k' -> repr a k (<->) :: Substractable repr => repr a k -> repr k' k' -> repr a k infixr 3 <-> class Dicurryable repr dicurry :: (Dicurryable repr, CurryN args) => proxy args -> (args -..-> r) -> (r -> Tuples args) -> repr (args -..-> k) k -> repr (r -> k) k dicurry :: (Dicurryable repr, Transformable repr) => Dicurryable (UnTrans repr) => CurryN args => proxy args -> (args -..-> r) -> (r -> Tuples args) -> repr (args -..-> k) k -> repr (r -> k) k construct :: forall args a k repr. Dicurryable repr => Generic a => EoTOfRep a => CurryN args => Tuples args ~ EoT (ADT a) => args ~ Args (args -..-> a) => (args -..-> a) -> repr (args -..-> k) k -> repr (a -> k) k module Symantic.Base.Fixity data Fixity Fixity1 :: Unifix -> Fixity Fixity2 :: Infix -> Fixity data Unifix Prefix :: Precedence -> Unifix [unifix_precedence] :: Unifix -> Precedence Postfix :: Precedence -> Unifix [unifix_precedence] :: Unifix -> Precedence data Infix Infix :: Maybe Associativity -> Precedence -> Infix [infix_associativity] :: Infix -> Maybe Associativity [infix_precedence] :: Infix -> Precedence infixL :: Precedence -> Infix infixR :: Precedence -> Infix infixB :: Side -> Precedence -> Infix infixN :: Precedence -> Infix infixN0 :: Infix infixN5 :: Infix -- | Given Precedence and Associativity of its parent -- operator, and the operand Side it is in, return whether an -- Infix operator needs to be enclosed by a Pair. isPairNeeded :: (Infix, Side) -> Infix -> Bool -- | If isPairNeeded is True, enclose the given -- IsString by given Pair, otherwise returns the same -- IsString. pairIfNeeded :: Semigroup s => IsString s => Pair -> (Infix, Side) -> Infix -> s -> s type Precedence = Int class PrecedenceOf a precedence :: PrecedenceOf a => a -> Precedence data Associativity -- | Associate to the left: a ¹ b ² c == (a ¹ b) ² c AssocL :: Associativity -- | Associate to the right: a ¹ b ² c == a ¹ (b ² c) AssocR :: Associativity -- | Associate to both sides, but to Side when reading. AssocB :: Side -> Associativity data Side -- | Left SideL :: Side -- | Right SideR :: Side type Pair = (String, String) pairAngle :: Pair pairBrace :: Pair pairBracket :: Pair pairParen :: Pair instance GHC.Show.Show Symantic.Base.Fixity.Fixity instance GHC.Classes.Eq Symantic.Base.Fixity.Fixity instance GHC.Show.Show Symantic.Base.Fixity.Infix instance GHC.Classes.Eq Symantic.Base.Fixity.Infix instance GHC.Show.Show Symantic.Base.Fixity.Associativity instance GHC.Classes.Eq Symantic.Base.Fixity.Associativity instance GHC.Show.Show Symantic.Base.Fixity.Side instance GHC.Classes.Eq Symantic.Base.Fixity.Side instance GHC.Show.Show Symantic.Base.Fixity.Unifix instance GHC.Classes.Eq Symantic.Base.Fixity.Unifix instance Symantic.Base.Fixity.PrecedenceOf Symantic.Base.Fixity.Fixity instance Symantic.Base.Fixity.PrecedenceOf Symantic.Base.Fixity.Infix instance Symantic.Base.Fixity.PrecedenceOf Symantic.Base.Fixity.Unifix module Symantic.Base.Permutable class Permutable repr where { type family Permutation (repr :: * -> * -> *) = (r :: * -> * -> *) | r -> repr; type Permutation repr = Permutation (UnTrans repr); } permutable :: Permutable repr => Permutation repr (a -> k) k -> repr (a -> k) k perm :: Permutable repr => repr (a -> k) k -> Permutation repr (a -> k) k noPerm :: Permutable repr => Permutation repr k k permWithDefault :: Permutable repr => a -> repr (a -> k) k -> Permutation repr (a -> k) k optionalPerm :: (Permutable repr, Eitherable repr) => Dimapable repr => Permutable repr => repr (a -> k) k -> Permutation repr (Maybe a -> k) k (<&>) :: Permutable repr => Tupable (Permutation repr) => repr (a -> k) k -> Permutation repr (b -> k) k -> Permutation repr ((a, b) -> k) k infixr 4 <&> () :: Eitherable repr => Dimapable repr => Permutable repr => Tupable (Permutation repr) => repr (a -> k) k -> Permutation repr (b -> k) k -> Permutation repr ((Maybe a, b) -> k) k infixr 4 (<*&>) :: Eitherable repr => Repeatable repr => Dimapable repr => Permutable repr => Tupable (Permutation repr) => repr (a -> k) k -> Permutation repr (b -> k) k -> Permutation repr (([a], b) -> k) k infixr 4 <*&> (<+&>) :: Eitherable repr => Repeatable repr => Dimapable repr => Permutable repr => Tupable (Permutation repr) => repr (a -> k) k -> Permutation repr (b -> k) k -> Permutation repr (([a], b) -> k) k infixr 4 <+&> module Symantic.Base.Routable class Routable repr () :: (Routable repr, Transformable repr) => Routable (UnTrans repr) => repr a k -> repr b k -> repr (a :!: b) k () :: Routable repr => repr a k -> repr b k -> repr (a :!: b) k infixr 3 -- | Like (,) but infixr. data (:!:) a b (:!:) :: a -> b -> (:!:) a b infixr 3 :!: infixr 3 :!: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (a Symantic.Base.Routable.:!: b) instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (a Symantic.Base.Routable.:!: b) module Symantic.Base