Explorer

core.type-infer-type-argument

description
Infer a type argument that is not entered (hole): from the other arguments whose parameter types contain parameter(name), in order (a lambda argument from the type of its body, with the type arguments known so far substituted into its parameter types), and otherwise from the expected type of the call and the return type (docs/type-arguments.md)
type
Fn(
  name: String,
  parameters: List<Record{name: String, type: @core.type-ast}>,
  arguments: List<Record{name: String, value: @core.expression}>,
  env: @core.type-env,
  index: Number,
  return_type: @core.type-ast,
  expected_type: Union{#none, #some(@core.type-ast)},
  known: List<Record{name: String, type: @core.type-ast}>
) -> Union{#none, #some(@core.type-ast)}
expression
fn(name$0, parameters$1, arguments$2, env$3, index$4, return_type$5, expected_type$6, known$20) =>
  match @core.list-get(list: $1, index: $4) {
    #none(_) =>
      match $6 {
        #some(expected$7) =>
          @core.type-match-parameter(pattern: $5, actual: $7, name: $0),
        _ =>
          #none
      },
    #some(parameter$8) =>
      match @core.call-argument-find(arguments: $2, name: $8.name, index: 0) {
        #some(value$9) =>
          match $9 {
            #hole(_) =>
              @core.type-infer-type-argument(
                name: $0,
                parameters: $1,
                arguments: $2,
                env: $3,
                index: @core.plus(left: $4, right: 1),
                return_type: $5,
                expected_type: $6,
                known: $20
              ),
            #function(lambda$21) =>
              match @core.type-resolve(type: @core.type-substitute(type: $8.type, arguments: $20), env: $3) {
                #function(lambda_type$22) =>
                  match @core.type-infer-function-body(fn_parameters: $21.parameters, ty_parameters: $22.parameters, body: $21.body, env: $3, index: 0) {
                    #some(body_type$23) =>
                      match @core.type-match-parameter(pattern: $22.return_type, actual: $23, name: $0) {
                        #some(found$24) =>
                          match @core.equal(left: $24, right: #parameter<@core.type-ast>($0)) {
                            true =>
                              @core.type-infer-type-argument(
                                name: $0,
                                parameters: $1,
                                arguments: $2,
                                env: $3,
                                index: @core.plus(left: $4, right: 1),
                                return_type: $5,
                                expected_type: $6,
                                known: $20
                              ),
                            false =>
                              #some($24)
                          },
                        _ =>
                          @core.type-infer-type-argument(
                            name: $0,
                            parameters: $1,
                            arguments: $2,
                            env: $3,
                            index: @core.plus(left: $4, right: 1),
                            return_type: $5,
                            expected_type: $6,
                            known: $20
                          )
                      },
                    _ =>
                      @core.type-infer-type-argument(
                        name: $0,
                        parameters: $1,
                        arguments: $2,
                        env: $3,
                        index: @core.plus(left: $4, right: 1),
                        return_type: $5,
                        expected_type: $6,
                        known: $20
                      )
                  },
                _ =>
                  @core.type-infer-type-argument(
                    name: $0,
                    parameters: $1,
                    arguments: $2,
                    env: $3,
                    index: @core.plus(left: $4, right: 1),
                    return_type: $5,
                    expected_type: $6,
                    known: $20
                  )
              },
            _ =>
              match @core.type-check(expr: $9, env: $3) {
                #ok(actual$10) =>
                  match @core.type-match-parameter(pattern: $8.type, actual: $10, name: $0) {
                    #some(found$11) =>
                      #some($11),
                    _ =>
                      @core.type-infer-type-argument(
                        name: $0,
                        parameters: $1,
                        arguments: $2,
                        env: $3,
                        index: @core.plus(left: $4, right: 1),
                        return_type: $5,
                        expected_type: $6,
                        known: $20
                      )
                  },
                _ =>
                  @core.type-infer-type-argument(
                    name: $0,
                    parameters: $1,
                    arguments: $2,
                    env: $3,
                    index: @core.plus(left: $4, right: 1),
                    return_type: $5,
                    expected_type: $6,
                    known: $20
                  )
              }
          },
        _ =>
          @core.type-infer-type-argument(
            name: $0,
            parameters: $1,
            arguments: $2,
            env: $3,
            index: @core.plus(left: $4, right: 1),
            return_type: $5,
            expected_type: $6,
            known: $20
          )
      }
  }
visibility
public
core.type-infer-type-argument (project definy, branch main, snapshot CfIAXM725tR74SWd4aoTUz4-JJQfqnllblZbQ2Sv204)
id: A-KIonbU1g5SCHIp_MCBix7slO-mKjGH3SbxrFQTX-8
content hash: pIJxfo9iK_cR-gZQucrb4KvKPYgIf6ZqPz9ytEugNtE