@ -41,7 +41,9 @@ function LetExp(pairs, body) {
return ( x . exprType === "Definition" ||
x . exprType === "FunctionDefinition" ) ;
} ) ) {
throw "let can only be used to bind things to names or functions" ;
throw Errors . JInternalError (
"let can only be used to bind things to names or functions"
) ;
}
this . exprType = "Let" ;
this . val = [ pairs , body ] ;
@ -174,34 +176,48 @@ function If(condition, thenexp, elseexp) {
function TypeVar ( name ) {
this . exprtype = "TypeVar" ;
this . name = name ;
this . exprType = "TypeVar" ;
return this ;
}
TypeVar . prototype = TypeExpression ;
function TypeOp ( name , params , body ) {
if ( ! _ . every ( params , _ . compose (
_ . partial ( _ . isEqual , "TypeVar" ) ,
_ . property ( "exprtype" ) ) ) ) {
throw errors . JInternalError (
"Parameters to a type operator must be type variables"
) ;
}
function TypeOp ( name ) {
this . name = name ;
this . params = params ;
this . body = body ;
this . val = name ;
this . exprType = "TypeOperator" ;
return this ;
}
function isTypeExpr ( expr ) {
if ( ! expr . exprType ) {
throw errors . JInternalError ( expr ) ;
}
return ( ( expr . exprType === "TypeOperator" ) ||
( expr . exprType === "TypeVar" ) ||
( expr . exprType === "TypeApplication" ) ) ;
}
TypeOp . prototype = TypeExpression ;
function TypeBinding ( expression , type ) {
this . expr = expression ;
function TypeApp ( expression , type ) {
if ( isTypeExpr ( expression ) ) {
throw errors . JInternalError (
"Left-hand-side of type application must not be in the type language"
) ;
}
if ( ! isTypeExpr ( type ) ) {
throw errors . JInternalError (
"Right-hand-side of type application must be a type expression"
) ;
}
this . expression = expression ;
this . type = type ;
this . exprType = "TypeApplication" ;
return this ;
}
TypeBinding . prototype = TypeExpression ;
TypeApp . prototype = TypeExpression ;
//Applies the function ``name'' to the list of parameters
function makeApp ( name , parameters ) {
@ -246,7 +262,8 @@ OPInfo = {"+" : [3, "Left"],
">>=" : [ 1 , "Left" ] ,
"<$>" : [ 1 , "Left" ] ,
"." : [ 1 , "Left" ] ,
"," : [ 1 , "Left" ] } ;
"," : [ 1 , "Left" ] ,
"->" : [ 1 , "Right" ] } ;
module . exports =
{
@ -270,6 +287,6 @@ module.exports =
gensym : gensym ,
TypeVar : TypeVar ,
TypeOp : TypeOp ,
TypeBinding : TypeBinding ,
TypeApp : TypeApp ,
Closure : Closure
} ;