public static IUnboundDecl Clone(this IUnboundDecl decl) { return(decl.Match <IUnboundDecl>( // atomic types are immutable, so we can reuse it atomic => atomic, func => func.CloneFunc(), record => { var fields = new Dictionary <string, IUnboundDecl>(); foreach (var field in record.Fields) { fields.Add(field.Key, field.Value.Clone()); } return new RecordType(fields); }, tuple => new TupleType(tuple.Fields.Select(field => field.Clone())), // named types are immutable, so we can reuse it named => named)); }
public static IBoundDecl Bind(BindingContext context, IUnboundDecl unbound) { return(unbound.Match <IBoundDecl>( // atomics are already bound atomic => atomic, func => { Bind(context, func); return func; }, record => { var fields = new Dictionary <string, IBoundDecl>(); foreach (var field in record.Fields) { fields.Add(field.Key, Bind(context, field.Value)); } return new BoundRecordType(fields); }, tuple => new BoundTupleType(tuple.Fields.Select(field => Bind(context, field))), named => BindNamed(context, named))); }