src/NFun/Types/FunnyType.cs
/// <summary>
/// Substitude concrete types to generic type definition (if it is)
///
/// Example:
/// generic:   Fun(T1, int)-> T0[];   solved: {int, text}
/// returns:   Fun(text,int)-> int[];
/// </summary>
Substitude concrete types to generic type definition (if it is)


Substitude concrete types to generic type definition ( if it is )
public static FunnyType SubstituteConcreteTypes(FunnyType genericOrNot, FunnyType[] solvedTypes) {
        switch (genericOrNot.BaseType)
        {
            case BaseFunnyType.Empty:
            case BaseFunnyType.Bool:
            case BaseFunnyType.Int16:
            case BaseFunnyType.Int32:
            case BaseFunnyType.Int64:
            case BaseFunnyType.UInt8:
            case BaseFunnyType.UInt16:
            case BaseFunnyType.UInt32:
            case BaseFunnyType.UInt64:
            case BaseFunnyType.Real:
            case BaseFunnyType.Char:
            case BaseFunnyType.Any:
                return genericOrNot;
            case BaseFunnyType.ArrayOf:
                return ArrayOf(SubstituteConcreteTypes(genericOrNot.ArrayTypeSpecification.FunnyType, solvedTypes));
            case BaseFunnyType.Fun:
                var outputTypes = new FunnyType[genericOrNot.FunTypeSpecification.Inputs.Length];
                for (int i = 0; i < genericOrNot.FunTypeSpecification.Inputs.Length; i++)
                    outputTypes[i] =
                        SubstituteConcreteTypes(genericOrNot.FunTypeSpecification.Inputs[i], solvedTypes);
                return Fun(
                    SubstituteConcreteTypes(genericOrNot.FunTypeSpecification.Output, solvedTypes),
                    outputTypes);
            case BaseFunnyType.Generic:
                return solvedTypes[genericOrNot.GenericId.Value];
            default:
                throw new ArgumentOutOfRangeException();
        }
    }
public static FunnyType SubstituteConcreteTypes ( FunnyType genericOrNot , FunnyType [ ] solvedTypes ) { switch ( genericOrNot . BaseType ) { case BaseFunnyType . Empty : case BaseFunnyType . Bool : case BaseFunnyType . Int16 : case BaseFunnyType . Int32 : case BaseFunnyType . Int64 : case BaseFunnyType . UInt8 : case BaseFunnyType . UInt16 : case BaseFunnyType . UInt32 : case BaseFunnyType . UInt64 : case BaseFunnyType . Real : case BaseFunnyType . Char : case BaseFunnyType . Any : return genericOrNot ; case BaseFunnyType . ArrayOf : return ArrayOf ( SubstituteConcreteTypes ( genericOrNot . ArrayTypeSpecification . FunnyType , solvedTypes ) ) ; case BaseFunnyType . Fun : var outputTypes = new FunnyType [ genericOrNot . FunTypeSpecification . Inputs . Length ] ; for ( int i = 0 ; i < genericOrNot . FunTypeSpecification . Inputs . Length ; i ++ ) outputTypes [ i ] = SubstituteConcreteTypes ( genericOrNot . FunTypeSpecification . Inputs [ i ] , solvedTypes ) ; return Fun ( SubstituteConcreteTypes ( genericOrNot . FunTypeSpecification . Output , solvedTypes ) , outputTypes ) ; case BaseFunnyType . Generic : return solvedTypes [ genericOrNot . GenericId . Value ] ; default : throw new ArgumentOutOfRangeException ( ) ; } }
Substitude concrete types to generic type definition (if it is)
Substitude concrete types to generic type definition ( if it is )
genericOrNot
FunnyType
solvedTypes
FunnyType[]