module Hydra.Impl.Haskell.Sources.Basics where

import Hydra.All
import Hydra.Impl.Haskell.Dsl.Base as Base
import Hydra.Impl.Haskell.Sources.Module
import Hydra.Impl.Haskell.Sources.Mantle
import qualified Hydra.Impl.Haskell.Dsl.Standard as Standard
import qualified Hydra.Impl.Haskell.Dsl.Types as Types
import Hydra.Impl.Haskell.Dsl.Lib.Lists as Lists
import Hydra.Impl.Haskell.Dsl.Lib.Strings as Strings


basicsNs :: Namespace
basicsNs = String -> Namespace
Namespace String
"hydra/basics"

basics :: String -> Datum a -> Definition a
basics :: forall a. String -> Datum a -> Definition a
basics = forall a. Name -> Datum a -> Definition a
Definition forall b c a. (b -> c) -> (a -> b) -> a -> c
. Namespace -> String -> Name
fromQname Namespace
basicsNs

hydraBasicsModule :: Module Meta
hydraBasicsModule :: Module Meta
hydraBasicsModule = forall m.
Namespace -> [Element m] -> [Module m] -> Maybe String -> Module m
Module Namespace
basicsNs [Element Meta]
elements [Module Meta
hydraMantleModule] forall a b. (a -> b) -> a -> b
$
    forall a. a -> Maybe a
Just String
"Basic functions for working with types and terms"
  where
    elements :: [Element Meta]
elements = [
      forall a. Definition a -> Element Meta
el forall m. Definition (Elimination m -> EliminationVariant)
eliminationVariantSource,
      forall a. Definition a -> Element Meta
el Definition [EliminationVariant]
eliminationVariantsSource,
      forall a. Definition a -> Element Meta
el Definition (FloatType -> Precision)
floatTypePrecisionSource,
      forall a. Definition a -> Element Meta
el Definition [FloatType]
floatTypesSource,
      forall a. Definition a -> Element Meta
el Definition (FloatValue -> FloatType)
floatValueTypeSource,
      forall a. Definition a -> Element Meta
el forall m. Definition (Function m -> FunctionVariant)
functionVariantSource,
      forall a. Definition a -> Element Meta
el Definition [FunctionVariant]
functionVariantsSource,
      forall a. Definition a -> Element Meta
el Definition (IntegerType -> Bool)
integerTypeIsSignedSource,
      forall a. Definition a -> Element Meta
el Definition (IntegerType -> Precision)
integerTypePrecisionSource,
      forall a. Definition a -> Element Meta
el Definition [IntegerType]
integerTypesSource,
      forall a. Definition a -> Element Meta
el Definition (IntegerValue -> IntegerType)
integerValueTypeSource,
      forall a. Definition a -> Element Meta
el Definition (Literal -> LiteralType)
literalTypeSource,
      forall a. Definition a -> Element Meta
el Definition (LiteralType -> LiteralVariant)
literalTypeVariantSource,
      forall a. Definition a -> Element Meta
el Definition (Literal -> LiteralVariant)
literalVariantSource,
      forall a. Definition a -> Element Meta
el Definition [LiteralVariant]
literalVariantsSource,
      forall a. Definition a -> Element Meta
el Definition (Namespace -> String -> Name)
qnameSource,
      forall a. Definition a -> Element Meta
el forall m. Definition (Term m -> TermVariant)
termVariantSource,
      forall a. Definition a -> Element Meta
el Definition [TermVariant]
termVariantsSource,
      forall a. Definition a -> Element Meta
el forall a. Definition ([[a]] -> Int)
testListsSource,
      forall a. Definition a -> Element Meta
el forall m. Definition (Type m -> TypeVariant)
typeVariantSource,
      forall a. Definition a -> Element Meta
el Definition [TypeVariant]
typeVariantsSource]

eliminationVariantSource :: Definition (Elimination m -> EliminationVariant)
eliminationVariantSource :: forall m. Definition (Elimination m -> EliminationVariant)
eliminationVariantSource = forall a. String -> Datum a -> Definition a
basics String
"eliminationVariant" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the elimination variant (constructor) for a given elimination term" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m -> Type m
Types.function (forall m. Type m -> Type m -> Type m
Types.apply (forall m. Name -> Type m
Types.nominal Name
_Elimination) (forall m. String -> Type m
Types.variable String
"m")) (forall m. Name -> Type m
Types.nominal Name
_EliminationVariant)) forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_Elimination Name
_EliminationVariant [
    FieldName
_Elimination_element  forall a b. a -> b -> (a, b)
@-> FieldName
_EliminationVariant_element,
    FieldName
_Elimination_list     forall a b. a -> b -> (a, b)
@-> FieldName
_EliminationVariant_list,
    FieldName
_Elimination_nominal  forall a b. a -> b -> (a, b)
@-> FieldName
_EliminationVariant_nominal,
    FieldName
_Elimination_optional forall a b. a -> b -> (a, b)
@-> FieldName
_EliminationVariant_optional,
    FieldName
_Elimination_record   forall a b. a -> b -> (a, b)
@-> FieldName
_EliminationVariant_record,
    FieldName
_Elimination_union    forall a b. a -> b -> (a, b)
@-> FieldName
_EliminationVariant_union]

eliminationVariantsSource :: Definition [EliminationVariant]
eliminationVariantsSource :: Definition [EliminationVariant]
eliminationVariantsSource = forall a. String -> Datum a -> Definition a
basics String
"eliminationVariants" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"All elimination variants (constructors), in a canonical order" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_EliminationVariant) forall a b. (a -> b) -> a -> b
$
  forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_EliminationVariant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
    FieldName
_EliminationVariant_element,
    FieldName
_EliminationVariant_list,
    FieldName
_EliminationVariant_nominal,
    FieldName
_EliminationVariant_optional,
    FieldName
_EliminationVariant_record,
    FieldName
_EliminationVariant_union]

floatTypePrecisionSource :: Definition (FloatType -> Precision)
floatTypePrecisionSource :: Definition (FloatType -> Precision)
floatTypePrecisionSource = forall a. String -> Datum a -> Definition a
basics String
"floatTypePrecision" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the precision of a given floating-point type" forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, Field Meta)] -> Datum (a -> b)
matchToUnion Name
_FloatType Name
_Precision [
    FieldName
_FloatType_bigfloat forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_arbitrary forall a. Datum a
unit,
    FieldName
_FloatType_float32  forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
32,
    FieldName
_FloatType_float64  forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
64]

floatTypesSource :: Definition [FloatType]
floatTypesSource :: Definition [FloatType]
floatTypesSource = forall a. String -> Datum a -> Definition a
basics String
"floatTypes" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"All floating-point types in a canonical order" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_FloatType) forall a b. (a -> b) -> a -> b
$
  forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_FloatType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
    FieldName
_FloatType_bigfloat,
    FieldName
_FloatType_float32,
    FieldName
_FloatType_float64]

floatValueTypeSource :: Definition (FloatValue -> FloatType)
floatValueTypeSource :: Definition (FloatValue -> FloatType)
floatValueTypeSource = forall a. String -> Datum a -> Definition a
basics String
"floatValueType" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the float type for a given floating-point value" forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_FloatValue Name
_FloatType [
    FieldName
_FloatValue_bigfloat forall a b. a -> b -> (a, b)
@-> FieldName
_FloatType_bigfloat,
    FieldName
_FloatValue_float32  forall a b. a -> b -> (a, b)
@-> FieldName
_FloatType_float32,
    FieldName
_FloatValue_float64  forall a b. a -> b -> (a, b)
@-> FieldName
_FloatType_float64]

functionVariantSource :: Definition (Function m -> FunctionVariant)
functionVariantSource :: forall m. Definition (Function m -> FunctionVariant)
functionVariantSource = forall a. String -> Datum a -> Definition a
basics String
"functionVariant" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the function variant (constructor) for a given function" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m -> Type m
Types.function (forall m. Type m -> Type m -> Type m
Types.apply (forall m. Name -> Type m
Types.nominal Name
_Function) (forall m. String -> Type m
Types.variable String
"m")) (forall m. Name -> Type m
Types.nominal Name
_FunctionVariant)) forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_Function Name
_FunctionVariant [
    FieldName
_Function_compareTo   forall a b. a -> b -> (a, b)
@-> FieldName
_FunctionVariant_compareTo,
    FieldName
_Function_elimination forall a b. a -> b -> (a, b)
@-> FieldName
_FunctionVariant_elimination,
    FieldName
_Function_lambda      forall a b. a -> b -> (a, b)
@-> FieldName
_FunctionVariant_lambda,
    FieldName
_Function_primitive   forall a b. a -> b -> (a, b)
@-> FieldName
_FunctionVariant_primitive]

functionVariantsSource :: Definition [FunctionVariant]
functionVariantsSource :: Definition [FunctionVariant]
functionVariantsSource = forall a. String -> Datum a -> Definition a
basics String
"functionVariants" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"All function variants (constructors), in a canonical order" forall a b. (a -> b) -> a -> b
$
    forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_FunctionVariant) forall a b. (a -> b) -> a -> b
$
  forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_FunctionVariant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
    FieldName
_FunctionVariant_compareTo,
    FieldName
_FunctionVariant_elimination,
    FieldName
_FunctionVariant_lambda,
    FieldName
_FunctionVariant_primitive]

integerTypeIsSignedSource :: Definition (IntegerType -> Bool)
integerTypeIsSignedSource :: Definition (IntegerType -> Bool)
integerTypeIsSignedSource = forall a. String -> Datum a -> Definition a
basics String
"integerTypeIsSigned" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find whether a given integer type is signed (true) or unsigned (false)" forall a b. (a -> b) -> a -> b
$
  forall x b a.
Name -> [(FieldName, Datum (x -> b))] -> Datum (a -> b)
matchData Name
_IntegerType [
    FieldName
_IntegerType_bigint forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
true,
    FieldName
_IntegerType_int8   forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
true,
    FieldName
_IntegerType_int16  forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
true,
    FieldName
_IntegerType_int32  forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
true,
    FieldName
_IntegerType_int64  forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
true,
    FieldName
_IntegerType_uint8  forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
false,
    FieldName
_IntegerType_uint16 forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
false,
    FieldName
_IntegerType_uint32 forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
false,
    FieldName
_IntegerType_uint64 forall a b. a -> b -> (a, b)
@-> forall a b. Datum a -> Datum (b -> a)
constant Datum Bool
false]

integerTypePrecisionSource :: Definition (IntegerType -> Precision)
integerTypePrecisionSource :: Definition (IntegerType -> Precision)
integerTypePrecisionSource = forall a. String -> Datum a -> Definition a
basics String
"integerTypePrecision" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the precision of a given integer type" forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, Field Meta)] -> Datum (a -> b)
matchToUnion Name
_IntegerType Name
_Precision [
    FieldName
_IntegerType_bigint forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_arbitrary forall a. Datum a
unit,
    FieldName
_IntegerType_int8   forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
8,
    FieldName
_IntegerType_int16  forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
16,
    FieldName
_IntegerType_int32  forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
32,
    FieldName
_IntegerType_int64  forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
64,
    FieldName
_IntegerType_uint8  forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
8,
    FieldName
_IntegerType_uint16 forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
16,
    FieldName
_IntegerType_uint32 forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
32,
    FieldName
_IntegerType_uint64 forall a b. a -> b -> (a, b)
@-> forall a. FieldName -> Datum a -> Field Meta
field FieldName
_Precision_bits forall a b. (a -> b) -> a -> b
$ Int -> Datum Int
int Int
64]

integerTypesSource :: Definition [IntegerType]
integerTypesSource :: Definition [IntegerType]
integerTypesSource = forall a. String -> Datum a -> Definition a
basics String
"integerTypes" forall a b. (a -> b) -> a -> b
$
    forall a. String -> Datum a -> Datum a
doc String
"All integer types, in a canonical order" forall a b. (a -> b) -> a -> b
$
    forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_IntegerType) forall a b. (a -> b) -> a -> b
$
    forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_IntegerType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
      FieldName
_IntegerType_bigint,
      FieldName
_IntegerType_int8,
      FieldName
_IntegerType_int16,
      FieldName
_IntegerType_int32,
      FieldName
_IntegerType_int64,
      FieldName
_IntegerType_uint8,
      FieldName
_IntegerType_uint16,
      FieldName
_IntegerType_uint32,
      FieldName
_IntegerType_uint64]

integerValueTypeSource :: Definition (IntegerValue -> IntegerType)
integerValueTypeSource :: Definition (IntegerValue -> IntegerType)
integerValueTypeSource = forall a. String -> Datum a -> Definition a
basics String
"integerValueType" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the integer type for a given integer value" forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_IntegerValue Name
_IntegerType [
    FieldName
_IntegerValue_bigint forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_bigint,
    FieldName
_IntegerValue_int8   forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_int8,
    FieldName
_IntegerValue_int16  forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_int16,
    FieldName
_IntegerValue_int32  forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_int32,
    FieldName
_IntegerValue_int64  forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_int64,
    FieldName
_IntegerValue_uint8  forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_uint8,
    FieldName
_IntegerValue_uint16 forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_uint16,
    FieldName
_IntegerValue_uint32 forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_uint32,
    FieldName
_IntegerValue_uint64 forall a b. a -> b -> (a, b)
@-> FieldName
_IntegerType_uint64]

literalTypeSource :: Definition (Literal -> LiteralType)
literalTypeSource :: Definition (Literal -> LiteralType)
literalTypeSource = forall a. String -> Datum a -> Definition a
basics String
"literalType" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the literal type for a given literal value" forall a b. (a -> b) -> a -> b
$
  forall u b. Name -> Type Meta -> [Field Meta] -> Datum (u -> b)
match Name
_Literal (forall m. Name -> Type m
Types.nominal Name
_LiteralType) [
    forall a. FieldName -> Case a
Case FieldName
_Literal_binary  forall a b. Case a -> Datum (a -> b) -> Field Meta
--> forall a b. Datum a -> Datum (b -> a)
constant forall a b. (a -> b) -> a -> b
$ forall a b. Name -> FieldName -> Datum a -> Datum b
variant Name
_LiteralType FieldName
_LiteralType_binary forall a. Datum a
unit,
    forall a. FieldName -> Case a
Case FieldName
_Literal_boolean forall a b. Case a -> Datum (a -> b) -> Field Meta
--> forall a b. Datum a -> Datum (b -> a)
constant forall a b. (a -> b) -> a -> b
$ forall a b. Name -> FieldName -> Datum a -> Datum b
variant Name
_LiteralType FieldName
_LiteralType_boolean forall a. Datum a
unit,
    forall a. FieldName -> Case a
Case FieldName
_Literal_float   forall a b. Case a -> Datum (a -> b) -> Field Meta
--> forall a b. Name -> FieldName -> Datum (a -> b)
union2 Name
_LiteralType FieldName
_LiteralType_float forall b c a. Datum (b -> c) -> Datum (a -> b) -> Datum (a -> c)
<.> forall a. Definition a -> Datum a
ref Definition (FloatValue -> FloatType)
floatValueTypeSource,
    forall a. FieldName -> Case a
Case FieldName
_Literal_integer forall a b. Case a -> Datum (a -> b) -> Field Meta
--> forall a b. Name -> FieldName -> Datum (a -> b)
union2 Name
_LiteralType FieldName
_LiteralType_integer forall b c a. Datum (b -> c) -> Datum (a -> b) -> Datum (a -> c)
<.> forall a. Definition a -> Datum a
ref Definition (IntegerValue -> IntegerType)
integerValueTypeSource,
    forall a. FieldName -> Case a
Case FieldName
_Literal_string  forall a b. Case a -> Datum (a -> b) -> Field Meta
--> forall a b. Datum a -> Datum (b -> a)
constant forall a b. (a -> b) -> a -> b
$ forall a b. Name -> FieldName -> Datum a -> Datum b
variant Name
_LiteralType FieldName
_LiteralType_string forall a. Datum a
unit]

literalTypeVariantSource :: Definition (LiteralType -> LiteralVariant)
literalTypeVariantSource :: Definition (LiteralType -> LiteralVariant)
literalTypeVariantSource = forall a. String -> Datum a -> Definition a
basics String
"literalTypeVariant" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the literal type variant (constructor) for a given literal value" forall a b. (a -> b) -> a -> b
$
  forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_LiteralType Name
_LiteralVariant [
    FieldName
_LiteralType_binary  forall a b. a -> b -> (a, b)
@-> FieldName
_LiteralVariant_binary,
    FieldName
_LiteralType_boolean forall a b. a -> b -> (a, b)
@-> FieldName
_LiteralVariant_boolean,
    FieldName
_LiteralType_float   forall a b. a -> b -> (a, b)
@-> FieldName
_LiteralVariant_float,
    FieldName
_LiteralType_integer forall a b. a -> b -> (a, b)
@-> FieldName
_LiteralVariant_integer,
    FieldName
_LiteralType_string  forall a b. a -> b -> (a, b)
@-> FieldName
_LiteralVariant_string]

literalVariantSource :: Definition (Literal -> LiteralVariant)
literalVariantSource :: Definition (Literal -> LiteralVariant)
literalVariantSource = forall a. String -> Datum a -> Definition a
basics String
"literalVariant" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the literal variant (constructor) for a given literal value" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Type Meta -> Datum a -> Datum a
function (forall m. Name -> Type m
Types.nominal Name
_Literal) (forall m. Name -> Type m
Types.nominal Name
_LiteralVariant) forall a b. (a -> b) -> a -> b
$
  forall a. Definition a -> Datum a
ref Definition (LiteralType -> LiteralVariant)
literalTypeVariantSource forall b c a. Datum (b -> c) -> Datum (a -> b) -> Datum (a -> c)
<.> forall a. Definition a -> Datum a
ref Definition (Literal -> LiteralType)
literalTypeSource

literalVariantsSource :: Definition [LiteralVariant]
literalVariantsSource :: Definition [LiteralVariant]
literalVariantsSource = forall a. String -> Datum a -> Definition a
basics String
"literalVariants" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"All literal variants, in a canonical order" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_LiteralVariant) forall a b. (a -> b) -> a -> b
$
  forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_LiteralVariant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
    FieldName
_LiteralVariant_binary,
    FieldName
_LiteralVariant_boolean,
    FieldName
_LiteralVariant_float,
    FieldName
_LiteralVariant_integer,
    FieldName
_LiteralVariant_string]

qnameSource :: Definition (Namespace -> String -> Name)
qnameSource :: Definition (Namespace -> String -> Name)
qnameSource = forall a. String -> Datum a -> Definition a
basics String
"qname" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Construct a qualified (dot-separated) name" forall a b. (a -> b) -> a -> b
$
  forall a. [Type Meta] -> Type Meta -> Datum a -> Datum a
functionN [forall m. Name -> Type m
Types.nominal Name
_Namespace, forall m. Type m
Types.string] (forall m. Name -> Type m
Types.nominal Name
_Name) forall a b. (a -> b) -> a -> b
$
  forall x a b. String -> Datum x -> Datum (a -> b)
lambda String
"ns" forall a b. (a -> b) -> a -> b
$
    forall x a b. String -> Datum x -> Datum (a -> b)
lambda String
"name" forall a b. (a -> b) -> a -> b
$
      forall a b. Name -> Datum a -> Datum b
nom Name
_Name forall a b. (a -> b) -> a -> b
$
        forall a b. Datum (a -> b) -> Datum a -> Datum b
apply Datum ([String] -> String)
cat forall a b. (a -> b) -> a -> b
$
          forall a. [Datum a] -> Datum [a]
list [forall a b. Datum (a -> b) -> Datum a -> Datum b
apply (forall a b. Name -> Datum (a -> b)
denom Name
_Namespace) (forall a. String -> Datum a
var String
"ns"), String -> Datum String
string String
".", forall a. String -> Datum a
var String
"name"]

termVariantSource :: Definition (Term m -> TermVariant)
termVariantSource :: forall m. Definition (Term m -> TermVariant)
termVariantSource = forall a. String -> Datum a -> Definition a
basics String
"termVariant" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the term variant (constructor) for a given term" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Type Meta -> Datum a -> Datum a
function (forall m. Type m -> Type m -> Type m
Types.apply (forall m. Name -> Type m
Types.nominal Name
_Term) (forall m. String -> Type m
Types.variable String
"m")) (forall m. Name -> Type m
Types.nominal Name
_TermVariant) forall a b. (a -> b) -> a -> b
$
  forall x a b. String -> Datum x -> Datum (a -> b)
lambda String
"term" forall a b. (a -> b) -> a -> b
$ forall a b. Datum (a -> b) -> Datum a -> Datum b
apply
    (forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_Term Name
_TermVariant [
      FieldName
_Term_annotated       forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_annotated,
      FieldName
_Term_application     forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_application,
      FieldName
_Term_element         forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_element,
      FieldName
_Term_function        forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_function,
      FieldName
_Term_let             forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_let,
      FieldName
_Term_list            forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_list,
      FieldName
_Term_literal         forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_literal,
      FieldName
_Term_map             forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_map,
      FieldName
_Term_nominal         forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_nominal,
      FieldName
_Term_optional        forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_optional,
      FieldName
_Term_product         forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_product,
      FieldName
_Term_record          forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_record,
      FieldName
_Term_set             forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_set,
      FieldName
_Term_stream          forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_stream,
      FieldName
_Term_sum             forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_sum,
      FieldName
_Term_union           forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_union,
      FieldName
_Term_variable        forall a b. a -> b -> (a, b)
@-> FieldName
_TermVariant_variable])
    (forall a. String -> Datum a
var String
"term")

termVariantsSource :: Definition [TermVariant]
termVariantsSource :: Definition [TermVariant]
termVariantsSource = forall a. String -> Datum a -> Definition a
basics String
"termVariants" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"All term (expression) variants, in a canonical order" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_TermVariant) forall a b. (a -> b) -> a -> b
$
  forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_TermVariant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
    FieldName
_TermVariant_annotated,
    FieldName
_TermVariant_application,
    FieldName
_TermVariant_literal,
    FieldName
_TermVariant_element,
    FieldName
_TermVariant_function,
    FieldName
_TermVariant_list,
    FieldName
_TermVariant_map,
    FieldName
_TermVariant_nominal,
    FieldName
_TermVariant_optional,
    FieldName
_TermVariant_product,
    FieldName
_TermVariant_record,
    FieldName
_TermVariant_set,
    FieldName
_TermVariant_stream,
    FieldName
_TermVariant_sum,
    FieldName
_TermVariant_union,
    FieldName
_TermVariant_variable]

-- TODO: remove once there are other polymorphic functions in use
testListsSource :: Definition ([[a]] -> Int)
testListsSource :: forall a. Definition ([[a]] -> Int)
testListsSource = forall a. String -> Datum a -> Definition a
basics String
"testLists" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"TODO: temporary. Just a token polymorphic function for testing" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Type Meta -> Datum a -> Datum a
function (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. String -> Type m
Types.variable String
"a") forall m. Type m
Types.int32 forall a b. (a -> b) -> a -> b
$
  (forall x a b. String -> Datum x -> Datum (a -> b)
lambda String
"els" (forall a b. Datum (a -> b) -> Datum a -> Datum b
apply forall a. Datum ([a] -> Int)
Lists.length (forall a b. Datum (a -> b) -> Datum a -> Datum b
apply forall a. Datum ([a] -> a)
Lists.concat forall a b. (a -> b) -> a -> b
$ forall a. String -> Datum a
var String
"els")))

typeVariantSource :: Definition (Type m -> TypeVariant)
typeVariantSource :: forall m. Definition (Type m -> TypeVariant)
typeVariantSource = forall a. String -> Datum a -> Definition a
basics String
"typeVariant" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"Find the type variant (constructor) for a given type" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Type Meta -> Datum a -> Datum a
function (forall m. Type m -> Type m -> Type m
Types.apply (forall m. Name -> Type m
Types.nominal Name
_Type) (forall m. String -> Type m
Types.variable String
"m")) (forall m. Name -> Type m
Types.nominal Name
_TypeVariant) forall a b. (a -> b) -> a -> b
$
  forall x a b. String -> Datum x -> Datum (a -> b)
lambda String
"typ" forall a b. (a -> b) -> a -> b
$ forall a b. Datum (a -> b) -> Datum a -> Datum b
apply
    (forall a b.
Name -> Name -> [(FieldName, FieldName)] -> Datum (a -> b)
matchToEnum Name
_Type Name
_TypeVariant [
      FieldName
_Type_annotated   forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_annotated,
      FieldName
_Type_application forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_application,
      FieldName
_Type_element     forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_element,
      FieldName
_Type_function    forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_function,
      FieldName
_Type_lambda      forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_lambda,
      FieldName
_Type_list        forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_list,
      FieldName
_Type_literal     forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_literal,
      FieldName
_Type_map         forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_map,
      FieldName
_Type_nominal     forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_nominal,
      FieldName
_Type_optional    forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_optional,
      FieldName
_Type_product     forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_product,
      FieldName
_Type_record      forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_record,
      FieldName
_Type_set         forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_set,
      FieldName
_Type_stream      forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_stream,
      FieldName
_Type_sum         forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_sum,
      FieldName
_Type_union       forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_union,
      FieldName
_Type_variable    forall a b. a -> b -> (a, b)
@-> FieldName
_TypeVariant_variable])
    (forall a. String -> Datum a
var String
"typ")

typeVariantsSource :: Definition [TypeVariant]
typeVariantsSource :: Definition [TypeVariant]
typeVariantsSource = forall a. String -> Datum a -> Definition a
basics String
"typeVariants" forall a b. (a -> b) -> a -> b
$
  forall a. String -> Datum a -> Datum a
doc String
"All type variants, in a canonical order" forall a b. (a -> b) -> a -> b
$
  forall a. Type Meta -> Datum a -> Datum a
typed (forall m. Type m -> Type m
Types.list forall a b. (a -> b) -> a -> b
$ forall m. Name -> Type m
Types.nominal Name
_TypeVariant) forall a b. (a -> b) -> a -> b
$
  forall a. [Datum a] -> Datum [a]
list forall a b. (a -> b) -> a -> b
$ forall a. Name -> FieldName -> Datum a
unitVariant Name
_TypeVariant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [
    FieldName
_TypeVariant_annotated,
    FieldName
_TypeVariant_application,
    FieldName
_TypeVariant_element,
    FieldName
_TypeVariant_function,
    FieldName
_TypeVariant_lambda,
    FieldName
_TypeVariant_list,
    FieldName
_TypeVariant_literal,
    FieldName
_TypeVariant_map,
    FieldName
_TypeVariant_nominal,
    FieldName
_TypeVariant_optional,
    FieldName
_TypeVariant_product,
    FieldName
_TypeVariant_record,
    FieldName
_TypeVariant_set,
    FieldName
_TypeVariant_stream,
    FieldName
_TypeVariant_sum,
    FieldName
_TypeVariant_union,
    FieldName
_TypeVariant_variable]