Esempio n. 1
0
        public string VisitFun(FunType f)
        {
            if (f.arrows.Count == 0)
            {
                return("? -> ?");
            }

            StringBuilder sb = new StringBuilder();

            int?num = ctr.Visit(f);

            if (num.HasValue)
            {
                sb.Append("#").Append(num.Value);
            }
            else
            {
                int newNum = ctr.Push(f);

                int           i    = 0;
                ISet <string> seen = new HashSet <string>();

                foreach (var e in f.arrows)
                {
                    DataType from   = e.Key;
                    string   sArrow = $"{from.Accept(this)} -> {e.Value.Accept(this)}";
                    if (!seen.Contains(sArrow))
                    {
                        if (i != 0)
                        {
                            if (this.multiline)
                            {
                                sb.Append("\n| ");
                            }
                            else
                            {
                                sb.Append(" | ");
                            }
                        }

                        sb.Append(sArrow);
                        seen.Add(sArrow);
                    }
                    i++;
                }

                if (ctr.isUsed(f))
                {
                    sb.Append("=#").Append(newNum).Append(": ");
                }
                ctr.Pop(f);
            }
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new FunType which is an awaitable version of this FunType.
        /// </summary>
        public FunType MakeAwaitable()
        {
            var fnAwaitable = new FunType(this.Definition, this.scope)
            {
                arrows       = this.arrows.ToDictionary(k => k.Key, v => (DataType) new AwaitableType(v.Value)),
                lambda       = this.lambda,
                Class        = this.Class,
                defaultTypes = this.defaultTypes
            };

            return(fnAwaitable);
        }