Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started changes to help typchecker doing typechecking

  • Loading branch information...
commit 93126f9e80fa5d4083ff56d447887eb252122326 1 parent a771d1c
Mikael Bung authored
View
21 haskell.ast.js
@@ -1,4 +1,4 @@
-(function(ast, interpreter, utilities) {
+(function(ast, interpreter, utilities, typechecker) {
expectType = utilities.expectType;
expectTypeOf = utilities.expectTypeOf;
@@ -422,7 +422,7 @@
/*
data Declaration = Variable Pattern Expression
| Function Identifier [Pattern] [(Guard, Expression)]|Expression
- | Data Identifier [Constructor]
+ | Data Identifier [TVar] [Constructor]
*/
ast.Declaration = function(){};
@@ -438,12 +438,14 @@
return this.pattern.stringify() + " = " + this.expression.stringify();
};
};
-
- ast.Data = function(identifier, constructors) {
+
+ ast.Data = function(identifier, tvars, constructors) {
expectTypeOf(identifier, "string");
+ expectTypeArray(tvars, typechecker.TVar);
expectTypeArray(constructors, ast.Constructor);
this.type = "Data";
this.identifier = identifier;
+ this.tvars = tvars;
this.constructors = constructors;
};
@@ -486,14 +488,15 @@
ast.Function.prototype = new ast.Declaration();
/*
- data Constructor = Constructor Identifier Integer
+ data Constructor = Constructor Identifier [Type]
*/
- ast.Constructor = function(identifier, num) {
+
+ ast.Constructor = function(identifier, types) {
expectTypeOf(identifier, "string");
- expectTypeOf(num, "number");
+ expectTypeArray(t, "number");
this.type = "Constructor";
this.identifier = identifier;
- this.number = num;
+ this.types = types;
};
/*
@@ -605,4 +608,4 @@
ast.Combined.prototype = new ast.Pattern();
ast.ConstantPattern.prototype = new ast.Pattern();
ast.Wildcard.prototype = new ast.Pattern();
-})(haskell.ast,haskell.interpreter, haskell.utilities);
+})(haskell.ast,haskell.interpreter, haskell.utilities, haskell.typechecker);
View
2  haskell.hiji.primitives.js
@@ -46,7 +46,7 @@
return env;
}));
- // hijiOutputLine# :: IO ()
+ // hijiOutputLine# :: a -> IO ()
env.bind("hijiOutputLine#", primitives.createPrimitive(env, 1,
function(env, args) {
var arg = args[0];
View
2  haskell.interpreter.js
@@ -31,7 +31,7 @@
else if (decl.type=="Data") {
for (var i in decl.constructors) {
constr = decl.constructors[i];
- env.bind(constr.identifier, primitives.createDataConstructorKludge(env, constr.identifier, constr.number));
+ env.bind(constr.identifier, primitives.createDataConstructorKludge(env, constr.identifier, constr.types.length));
}
}
}
View
24 haskell.parser.js
@@ -1,6 +1,6 @@
// The parser
-(function(parser, ast) {
+(function(parser, ast, typechecker) {
parser.lastInternalName = 0;
parser.generateInternalName = function() {
@@ -782,8 +782,8 @@
var constr_action = function(p) {
return action(p, function(ast) {
- var name = ast[0];
- var count = ast[1].length;
+ var name = ast[0];
+ var arguments = ast[1];
return new haskell.ast.Constructor(name, arguments);
});
};
@@ -840,14 +840,24 @@
"[]",
"(->)",
sequence(ws('('), repeat1(ws(',')), ws(')'))
+ );
+
+
+
+
+
+ var atype_list_action = function(p) {
+ return action(p, function(ast) {
+ return new typechecker.TAp(new typechecker.TCon("([])", new typechecker.Kfun(new typechecker.Star(), new typechecker.Star())), ast[0]));
+ });
};
// redefinition
atype = choice( gtycon,
- tyvar,
- sequence(ws('('), list(ws(type), ','), ws(')')),
- sequence(ws('['), ws(type), ws(']')),
+ tyvar,
+ sequence(expectws('('), list(ws(type), ws(',')), expectws(')')),
+ atype_list_action(sequence(expectws('['), ws(type), expectws(']'))),
sequence(expectws('('), ws(type), expectws(')'))
);
@@ -1353,4 +1363,4 @@
var result = grammar(ps(contextFree));
return result;
- };
+ };

0 comments on commit 93126f9

Please sign in to comment.
Something went wrong with that request. Please try again.