diff --git a/src/ast.ts b/src/ast.ts index 07caf77..b42906b 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -344,7 +344,9 @@ export function prettyPrint(ast: AST, indent = 0): string { case 'definition': const ann = ast.annotation - ? ` : ${prettyPrintType(ast.annotation.type)}` + ? ` : ${ast.annotation.constraints.length > 0 + ? ast.annotation.constraints.map(c => `${c.className} ${c.typeVar}`).join(', ') + ' :: ' + : ''}${prettyPrintType(ast.annotation.type)}` : ''; if (!ast.body) return `${ast.name}${ann};`; return `${ast.name}${ann} = ${prettyPrint(ast.body, indent)};`; diff --git a/src/parser.ts b/src/parser.ts index ea2d162..5b258b8 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -185,7 +185,9 @@ export class Parser { let annotation: Annotation | undefined; if (this.current().kind === 'colon') { this.advance(); - annotation = { constraints: this.parsedConstraints, type: this.parseType() }; + const constraints = this.tryParseConstraints(); + const type = this.parseType(); + annotation = { constraints, type }; // Declaration only if (this.current().kind === 'semicolon') { @@ -633,8 +635,6 @@ export class Parser { private parseType(): TypeAST { // Check for constraints: Num a, Eq b :: - this.parsedConstraints = this.tryParseConstraints(); - const left = this.parseTypeApply(); if (this.current().kind === 'backslash') {