// Path: src/main/java/inference/Substitution.java
// public class Substitution extends Substitutable<Substitution> {
//     private HashMap<TVariable, Type> subs = new HashMap<>();
// 
//     public Substitution() {}
// 
//     public Substitution(TVariable variable, Type type) {
//         subs.put(variable, type);
//     }
// 
//     private Substitution(Substitution previous) {
//         subs.putAll(previous.subs);
//     }
// 
//     public Substitution(List<TVariable> vars, List<Type> substitute) {
//         if(vars.size() != substitute.size())
//             throw new IllegalArgumentException("Number of variables have to match number of types");
// 
//         for (int i = 0; i < vars.size(); i++) subs.put(vars.get(i), substitute.get(i));
//     }
// 
//     public List<TVariable> variables() {
//         return new LinkedList<>(subs.keySet());
//     }
// 
//     public Type substituteOf(TVariable var) {
//         return subs.get(var);
//     }
// 
//     public Substitution composeWith(Substitution sub) {
//         Substitution substituted = new Substitution(sub);
//         substituted.apply(this);
//         subs.putAll(substituted.subs);
//         return this;
//     }
// 
//     @Override
//     public HashSet<TVariable> ftv() {
//         HashSet<TVariable> freeVars = new HashSet<>();
//         for (TVariable var : variables()) freeVars.addAll(substituteOf(var).ftv());
//         return freeVars;
//     }
// 
//     @Override
//     public Substitution substitute(TVariable var, Type t) {
//         for (TVariable variable : variables())
//             subs.replace(variable, substituteOf(variable).substitute(var, t));
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return subs.toString();
//     }
// 
//     @Override
//     public Substitution identity() {
//         return this;
//     }
// }


import inference.Substitution;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
package types;



/**
 * Created by valentin on 18/10/2016.
 *
 * Constructeur de type. Ceci n'est pas utilisé pour le moment.
 */
public class  TConstructor extends Type {
    private final static Map<String, TConstructor> instantiated = new HashMap<>();
    private final String name;

    private TConstructor(String name) {
        System.out.println("Creation of TConstructor(" + name + ")");
        this.name = name;
    }

    public static TConstructor constructor(String name) {
        TConstructor cons = instantiated.get(name);
        if(cons == null) {
            cons = new TConstructor(name);
            instantiated.put(name, cons);
        }
        return cons;
    }

    public String name() {
        return name;
    }

    @Override
// Path: src/main/java/inference/Substitution.java
// public class Substitution extends Substitutable<Substitution> {
//     private HashMap<TVariable, Type> subs = new HashMap<>();
// 
//     public Substitution() {}
// 
//     public Substitution(TVariable variable, Type type) {
//         subs.put(variable, type);
//     }
// 
//     private Substitution(Substitution previous) {
//         subs.putAll(previous.subs);
//     }
// 
//     public Substitution(List<TVariable> vars, List<Type> substitute) {
//         if(vars.size() != substitute.size())
//             throw new IllegalArgumentException("Number of variables have to match number of types");
// 
//         for (int i = 0; i < vars.size(); i++) subs.put(vars.get(i), substitute.get(i));
//     }
// 
//     public List<TVariable> variables() {
//         return new LinkedList<>(subs.keySet());
//     }
// 
//     public Type substituteOf(TVariable var) {
//         return subs.get(var);
//     }
// 
//     public Substitution composeWith(Substitution sub) {
//         Substitution substituted = new Substitution(sub);
//         substituted.apply(this);
//         subs.putAll(substituted.subs);
//         return this;
//     }
// 
//     @Override
//     public HashSet<TVariable> ftv() {
//         HashSet<TVariable> freeVars = new HashSet<>();
//         for (TVariable var : variables()) freeVars.addAll(substituteOf(var).ftv());
//         return freeVars;
//     }
// 
//     @Override
//     public Substitution substitute(TVariable var, Type t) {
//         for (TVariable variable : variables())
//             subs.replace(variable, substituteOf(variable).substitute(var, t));
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return subs.toString();
//     }
// 
//     @Override
//     public Substitution identity() {
//         return this;
//     }
// }


// Path: src/main/java/types/TConstructor.java
import inference.Substitution;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

package types;



/**
 * Created by valentin on 18/10/2016.
 *
 * Constructeur de type. Ceci n'est pas utilisé pour le moment.
 */
public class  TConstructor extends Type {
    private final static Map<String, TConstructor> instantiated = new HashMap<>();
    private final String name;

    private TConstructor(String name) {
        System.out.println("Creation of TConstructor(" + name + ")");
        this.name = name;
    }

    public static TConstructor constructor(String name) {
        TConstructor cons = instantiated.get(name);
        if(cons == null) {
            cons = new TConstructor(name);
            instantiated.put(name, cons);
        }
        return cons;
    }

    public String name() {
        return name;
    }

    @Override
    public Type apply(Substitution substitution) {