hydra-kernel-0.16.1: src/main/haskell/Hydra/Decode/Typing.hs
-- Note: this is an automatically generated file. Do not edit.
-- | Term decoders for hydra.typing
module Hydra.Decode.Typing where
import qualified Hydra.Core as Core
import qualified Hydra.Decode.Core as DecodeCore
import qualified Hydra.Decode.Paths as Paths
import qualified Hydra.Errors as Errors
import qualified Hydra.Extract.Core as ExtractCore
import qualified Hydra.Graph as Graph
import qualified Hydra.Lexical as Lexical
import qualified Hydra.Haskell.Lib.Eithers as Eithers
import qualified Hydra.Rewriting as Rewriting
import qualified Hydra.Typing as Typing
import qualified Hydra.Util as Util
import Prelude hiding (Enum, Ordering, decodeFloat, encodeFloat, fail, map, pure, sum)
import qualified Data.Scientific as Sci
-- | Decoder for hydra.typing.FunctionStructure
functionStructure :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError env) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Typing.FunctionStructure env)
functionStructure env cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "typeParams" (ExtractCore.decodeList DecodeCore.name) fieldMap cx) (\field_typeParams -> Eithers.bind (ExtractCore.requireField "params" (ExtractCore.decodeList DecodeCore.name) fieldMap cx) (\field_params -> Eithers.bind (ExtractCore.requireField "bindings" (ExtractCore.decodeList DecodeCore.binding) fieldMap cx) (\field_bindings -> Eithers.bind (ExtractCore.requireField "body" DecodeCore.term fieldMap cx) (\field_body -> Eithers.bind (ExtractCore.requireField "domains" (ExtractCore.decodeList DecodeCore.type_) fieldMap cx) (\field_domains -> Eithers.bind (ExtractCore.requireField "codomain" (ExtractCore.decodeMaybe DecodeCore.type_) fieldMap cx) (\field_codomain -> Eithers.bind (ExtractCore.requireField "environment" env fieldMap cx) (\field_environment -> Right (Typing.FunctionStructure {
Typing.functionStructureTypeParams = field_typeParams,
Typing.functionStructureParams = field_params,
Typing.functionStructureBindings = field_bindings,
Typing.functionStructureBody = field_body,
Typing.functionStructureDomains = field_domains,
Typing.functionStructureCodomain = field_codomain,
Typing.functionStructureEnvironment = field_environment})))))))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.FunctionStructure")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.InferenceContext
inferenceContext :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.InferenceContext
inferenceContext cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "freshTypeVariableCount" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralInteger v2 -> case v2 of
Core.IntegerValueInt32 v3 -> Right v3
_ -> Left (Errors.DecodingError "expected int32 value")
_ -> Left (Errors.DecodingError "expected int32 literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_freshTypeVariableCount -> Eithers.bind (ExtractCore.requireField "trace" (ExtractCore.decodeList Paths.subtermStep) fieldMap cx) (\field_trace -> Right (Typing.InferenceContext {
Typing.inferenceContextFreshTypeVariableCount = field_freshTypeVariableCount,
Typing.inferenceContextTrace = field_trace}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.InferenceContext")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.InferenceResult
inferenceResult :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.InferenceResult
inferenceResult cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "term" DecodeCore.term fieldMap cx) (\field_term -> Eithers.bind (ExtractCore.requireField "type" DecodeCore.type_ fieldMap cx) (\field_type -> Eithers.bind (ExtractCore.requireField "subst" typeSubst fieldMap cx) (\field_subst -> Eithers.bind (ExtractCore.requireField "classConstraints" (ExtractCore.decodeMap DecodeCore.name DecodeCore.typeVariableConstraints) fieldMap cx) (\field_classConstraints -> Eithers.bind (ExtractCore.requireField "context" inferenceContext fieldMap cx) (\field_context -> Right (Typing.InferenceResult {
Typing.inferenceResultTerm = field_term,
Typing.inferenceResultType = field_type,
Typing.inferenceResultSubst = field_subst,
Typing.inferenceResultClassConstraints = field_classConstraints,
Typing.inferenceResultContext = field_context})))))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.InferenceResult")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.Parameter
parameter :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.Parameter
parameter cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "name" DecodeCore.name fieldMap cx) (\field_name -> Eithers.bind (ExtractCore.requireField "description" (ExtractCore.decodeMaybe (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2))) fieldMap cx) (\field_description -> Eithers.bind (ExtractCore.requireField "type" DecodeCore.type_ fieldMap cx) (\field_type -> Eithers.bind (ExtractCore.requireField "isLazy" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralBoolean v2 -> Right v2
_ -> Left (Errors.DecodingError "expected boolean literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_isLazy -> Right (Typing.Parameter {
Typing.parameterName = field_name,
Typing.parameterDescription = field_description,
Typing.parameterType = field_type,
Typing.parameterIsLazy = field_isLazy}))))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.Parameter")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.Result
result :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.Result
result cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "description" (ExtractCore.decodeMaybe (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2))) fieldMap cx) (\field_description -> Eithers.bind (ExtractCore.requireField "type" DecodeCore.type_ fieldMap cx) (\field_type -> Right (Typing.Result {
Typing.resultDescription = field_description,
Typing.resultType = field_type}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.Result")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.TermSignature
termSignature :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.TermSignature
termSignature cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "typeParameters" (ExtractCore.decodeList typeParameter) fieldMap cx) (\field_typeParameters -> Eithers.bind (ExtractCore.requireField "parameters" (ExtractCore.decodeList parameter) fieldMap cx) (\field_parameters -> Eithers.bind (ExtractCore.requireField "result" result fieldMap cx) (\field_result -> Right (Typing.TermSignature {
Typing.termSignatureTypeParameters = field_typeParameters,
Typing.termSignatureParameters = field_parameters,
Typing.termSignatureResult = field_result})))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.TermSignature")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.TermSubst
termSubst :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.TermSubst
termSubst cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermWrap v0 -> Eithers.map (\b -> Typing.TermSubst b) (ExtractCore.decodeMap DecodeCore.name DecodeCore.term cx (Core.wrappedTermBody v0))
_ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.TypeClass
typeClass :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.TypeClass
typeClass cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "description" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_description -> Right (Typing.TypeClass {
Typing.typeClassDescription = field_description})))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.TypeClass")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.TypeConstraint
typeConstraint :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.TypeConstraint
typeConstraint cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "left" DecodeCore.type_ fieldMap cx) (\field_left -> Eithers.bind (ExtractCore.requireField "right" DecodeCore.type_ fieldMap cx) (\field_right -> Eithers.bind (ExtractCore.requireField "comment" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_comment -> Right (Typing.TypeConstraint {
Typing.typeConstraintLeft = field_left,
Typing.typeConstraintRight = field_right,
Typing.typeConstraintComment = field_comment})))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.TypeConstraint")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.TypeParameter
typeParameter :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.TypeParameter
typeParameter cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "name" DecodeCore.name fieldMap cx) (\field_name -> Eithers.bind (ExtractCore.requireField "constraints" (ExtractCore.decodeList DecodeCore.typeClassConstraint) fieldMap cx) (\field_constraints -> Right (Typing.TypeParameter {
Typing.typeParameterName = field_name,
Typing.typeParameterConstraints = field_constraints}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.typing.TypeParameter")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.typing.TypeSubst
typeSubst :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Typing.TypeSubst
typeSubst cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermWrap v0 -> Eithers.map (\b -> Typing.TypeSubst b) (ExtractCore.decodeMap DecodeCore.name DecodeCore.type_ cx (Core.wrappedTermBody v0))
_ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)