Go to the documentation of this file. 1 package com.cliffc.aa.HM;
7 import java.util.Arrays;
8 import java.util.HashMap;
9 import java.util.HashSet;
68 static final HashMap<String,HMType>
ENV =
new HashMap<>();
98 return prog.
hm(
new HashSet<>());
121 throw new RuntimeException(
"Parse error, "+
_name+
" is undefined");
183 HashMap<HMType,HMType> vars =
new HashMap<>();
184 return _fresh(nongen,vars);
188 if( t2 instanceof
HMVar ) {
191 : vars.computeIfAbsent(t2, e ->
new HMVar(((
HMVar)t2)._t));
195 for(
int i=0; i<args.length; i++ )
214 if( y instanceof
Oper )
230 if(
_u!=
null ) s +=
">>"+
_u;
233 @Override
public String
_str() {
241 if( u==
null )
return this;
242 if( u.
_u==
null )
return u;
244 while( u.
_u!=
null ) u = u.
_u;
251 if( that instanceof
HMVar ) that = that.
find();
252 if(
this==that )
return this;
254 throw new RuntimeException(
"recursive unification");
256 if( that instanceof
HMVar ) {
274 @Override
public String
_str() {
275 if(
_name.equals(
"->") )
279 sb.
p(t.str()).
p(
',');
285 if( !(that instanceof
Oper) )
return that.
union(
this);
289 throw new RuntimeException(
"Cannot unify "+
this+
" and "+that);
290 for(
int i=0; i<
_args.length; i++ )
HMType hm(HashSet< HMVar > nongen)
HMType hm(HashSet< HMVar > nongen)
an implementation of language AA
static final HashMap< String, HMType > ENV
Apply(Syntax fun, Syntax arg)
Let(String arg0, Syntax body, Syntax use)
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
abstract HMType union(HMType t)
HMType _fresh(HashSet< HMVar > nongen, HashMap< HMType, HMType > vars)
abstract HMType hm(HashSet< HMVar > nongen)
static final TypeInt INT64
boolean occurs_in(HashSet< HMVar >nongen)
Lambda(String arg0, Syntax body)
boolean occurs_in_type(HMType v)
Tight/tiny StringBuilder wrapper.
HMType hm(HashSet< HMVar > nongen)
HMType hm(HashSet< HMVar > nongen)
HMType union(HMType that)
boolean occurs_in(HMType[] args)
Oper(String name, HMType... args)
static Oper fun(HMType... args)
static final TypeMemPtr STRPTR
static HMType hm(Syntax prog)
HMType hm(HashSet< HMVar > nongen)
static final TypeInt BOOL
static final TypeFlt FLT64
HMType fresh(HashSet< HMVar > nongen)