Exemplo n.º 1
0
 public IType CheckApp(IType type1, IKind kind, IType type2)
 {
     /*
     (TApp (TCPoly kind2) (TAbs unique type6)) = type1;
     return CheckPolymorphicTypeApp(kind2, kind, unique, type6, type2);
     */
     if (type1 is TApp)
     {
         IType type4 = ((TApp)type1).Function;
         IType type5 = ((TApp)type1).Argument;
         if (type4 is TCPoly)
         {
             IKind kind2 = ((TCPoly)type4).Kind;
             if (type5 is TAbs)
             {
                 Unique unique = ((TAbs)type5).Parameter;
                 IType type6 = ((TAbs)type5).Body;
                 return CheckPolymorphicTypeApp(
                     kind2, kind, unique, type6, type2
                 );
             }
         }
     }
     throw new ArgumentException(
         string.Format(
             "{0} doesn't have a polymorphic type", mValueExpr.Show()
         )
     );
 }
Exemplo n.º 2
0
        public IKind <OptionF, TB> Ap <TA, TB>(IKind <OptionF, Func <TA, TB> > ff, IKind <OptionF, TA> fa)
        {
            var f = ff.Fix();
            var a = fa.Fix();

            return(f.IsSome && a.IsSome
                ? (IKind <OptionF, TB>) new Some <TB>(f.Get()(a.Get()))
                : new None <TB>());
        }
Exemplo n.º 3
0
 public VETypeAbs(
     string typeVarName,
     IKind kind,
     IValueExpr valueExpr
 )
 {
     mTypeVarName = typeVarName;
     mKind = kind;
     mValueExpr = valueExpr;
 }
Exemplo n.º 4
0
 public bool Equals(IKind kind)
 {
     if (!(kind is KArrow))
     {
         return false;
     }
     IKind kind1 = ((KArrow)kind).mKind1;
     IKind kind2 = ((KArrow)kind).mKind2;
     return mKind1.Equals(kind1) && mKind2.Equals(kind2);
 }
Exemplo n.º 5
0
 public TEAbs(
     string typeVarName,
     IKind kind,
     ITypeExpr typeExpr
 )
 {
     mTypeVarName = typeVarName;
     mKind = kind;
     mTypeExpr = typeExpr;
 }
Exemplo n.º 6
0
 private IKind CheckFuncKindApp(
     IKind parameterKind,
     IKind returnKind,
     IKind argumentKind
 )
 {
     if (!argumentKind.Equals(parameterKind))
     {
         throw new ArgumentException(
             string.Format(
                 "unexpected {0}, expected {1}",
                 argumentKind.Show(),
                 parameterKind.Show()
             )
         );
     }
     return returnKind;
 }
Exemplo n.º 7
0
 private IKind CheckApp(IKind kind1, IKind kind2)
 {
     /*
     (KArrow kind3 kind4) = kind1;
     return CheckFuncKindApp(kind3, kind4, kind2);
     */
     if (kind1 is KArrow)
     {
         IKind kind3 = ((KArrow)kind1).Left;
         IKind kind4 = ((KArrow)kind1).Right;
         return CheckFuncKindApp(kind3, kind4, kind2);
     }
     throw new InvalidOperationException(
         string.Format(
             "{0} doesn't have a function kind", mTypeExpr1.Show()
         )
     );
 }
Exemplo n.º 8
0
 public IType CheckPolymorphicTypeApp(
     IKind parameterKind,
     IKind argumentKind,
     Unique parameter,
     IType body,
     IType argument
 )
 {
     if (!argumentKind.Equals(parameterKind))
     {
         throw new ArgumentException(
             string.Format(
                 "unexpected {0}, expected {1}",
                 argumentKind.Show(),
                 parameterKind.Show()
             )
         );
     }
     return body.Eval(parameter, argument);
 }
Exemplo n.º 9
0
 public bool EqK <T>(IKind <OptionF, T> x, IKind <OptionF, T> y, IEq <T> eq) =>
 OptionK.Eq(eq).Eqv(x.Fix(), y.Fix());
Exemplo n.º 10
0
 public static Try <T> Fix <T>(this IKind <TryF, T> self) => (Try <T>)self;
Exemplo n.º 11
0
 public TEPoly(IKind kind)
 {
     mKind = kind;
 }
Exemplo n.º 12
0
 public IKind <ResultOkF <TError>, TB> FlatMap <TA, TB>(
     IKind <ResultOkF <TError>, TA> fa, Func <TA, IKind <ResultOkF <TError>, TB> > f) =>
 fa.Fix().FlatMap(x => f(x).Fix());
Exemplo n.º 13
0
 public IKind <ResultOkF <TError>, TB> Ap <TA, TB>(IKind <ResultOkF <TError>, Func <TA, TB> > ff,
                                                   IKind <ResultOkF <TError>, TA> fa) =>
 ff.Fix().FlatMap(fa.Fix().Map);
Exemplo n.º 14
0
 public IKind <OptionF, TB> Map <TA, TB>(IKind <OptionF, TA> fa, Func <TA, TB> f) =>
 fa.Fix().Map(f);
Exemplo n.º 15
0
 public static Result <TOk, TError> Fix <TOk, TError>(this IKind <ResultOkF <TError>, TOk> self) =>
 (Result <TOk, TError>)self;
Exemplo n.º 16
0
 public IKind <ResultOkF <TError>, TB> Map <TA, TB>(IKind <ResultOkF <TError>, TA> fa, Func <TA, TB> f) =>
 fa.Fix().Map(f);
Exemplo n.º 17
0
 public void Add(string valueVarName, IKind kind)
 {
     mDictionary.Add(valueVarName, kind);
 }
Exemplo n.º 18
0
 public bool Equals(IKind kind)
 {
     return this == kind;
 }
Exemplo n.º 19
0
 public TypeVariableIntro(string name, IKind kind)
 {
     this.Name = name;
     this.Kind = kind;
 }
Exemplo n.º 20
0
 public static List <T> Fix <T>(this IKind <ListF, T> self) => ((ListK <T>)self).List;
Exemplo n.º 21
0
 public static Option <T> Fix <T>(this IKind <OptionF, T> self) => (Option <T>)self;
Exemplo n.º 22
0
 public static IType MakePolymorphicType(
     Unique unique, IKind kind, IType type
 )
 {
     return new TApp(new TCPoly(kind), new TAbs(unique, type));
 }
Exemplo n.º 23
0
 public IKind <OptionF, TB> XMap <TA, TB>(IKind <OptionF, TA> fa, Func <TA, TB> f, Func <TB, TA> g) =>
 fa.Fix().Map(f);
Exemplo n.º 24
0
 public bool TryGetValue(string valueVarName, out IKind result)
 {
     return mDictionary.TryGetValue(valueVarName, out result)
       || mParent.TryGetValue(valueVarName, out result);
 }
Exemplo n.º 25
0
 public IKind <TreeF, TB> Map <TA, TB>(IKind <TreeF, TA> fa, Func <TA, TB> f) =>
 fa.Fix() switch
 {
Exemplo n.º 26
0
 public ArrowKind(IKind left, IKind right)
 {
     this.Func = left;
     this.Arg  = right;
 }
Exemplo n.º 27
0
 public IKind <OptionF, TB> FlatMap <TA, TB>(IKind <OptionF, TA> fa, Func <TA, IKind <OptionF, TB> > f) =>
 fa.Fix().FlatMap(x => f(x).Fix());
Exemplo n.º 28
0
 public KArrow(IKind kind1, IKind kind2)
 {
     mKind1 = kind1;
     mKind2 = kind2;
 }
 private TypeInference AddIntro(string name, IKind kind) =>
 new TypeInference(this._state.Push(new TypeVariableIntro(name, kind)));
Exemplo n.º 30
0
 public IKind <TryF, TB> Ap <TA, TB>(IKind <TryF, Func <TA, TB> > ff, IKind <TryF, TA> fa) =>
 ff.Fix().FlatMap(fa.Fix().Map);