From 4ba55277a99542d245568da989b5217b04262f26 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 1 Feb 2023 21:22:23 +0100 Subject: Remove ambiguity from function definition syntax: Type (x y) could have Type as kind *->*, or (x y) could be the rhs --- doc/docs/frontend/syntax.md | 12 ++++++------ example.txt | 30 +++++++++++++++--------------- snug-clean/src/Snug/Parse.icl | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/doc/docs/frontend/syntax.md b/doc/docs/frontend/syntax.md index 836201c..17436af 100644 --- a/doc/docs/frontend/syntax.md +++ b/doc/docs/frontend/syntax.md @@ -40,19 +40,19 @@ Type synonyms can be defined with: ## Functions ```snug -(fun length ((xs : List a)) : Int - (length_acc 0 xs)) +(fun length ((xs : List a)) : Int : + length_acc 0 xs) -(fun length_acc ((n : Int) (xs : List a)) : Int - (case xs ( +(fun length_acc ((n : Int) (xs : List a)) : Int : + case xs ( (Nil -> n) - (Cons _ xs -> length_acc (+ n 1) xs)))) + (Cons _ xs -> length_acc (+ n 1) xs))) ``` In abstract terms, the syntax is: ```snug -(fun NAME (ARGUMENTS) : TYPE (EXPRESSION)) +(fun NAME (ARGUMENTS) : TYPE : EXPRESSION) ``` where arguments are of the form `(NAME : TYPE)`. diff --git a/example.txt b/example.txt index 26fc2d8..5aa858a 100644 --- a/example.txt +++ b/example.txt @@ -41,15 +41,15 @@ (DataDef TypeIdent (List TypeVarIdent) (List ConstructorDef)) (FunDef SymbolIdent (List (Tuple SymbolIdent Type)) Type Expression))) -(fun list_ast () : Definition - (DataDef +(fun list_ast () : Definition : + DataDef (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil)))) (Cons (Cons 'a' Nil) Nil) (Cons (ConstructorDef (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) (Cons (ConstructorDef (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons (TypeVar (Cons 'a' Nil)) (Cons (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil))) Nil))) - Nil)))) -(fun length_acc_ast () : Definition - (FunDef + Nil))) +(fun length_acc_ast () : Definition : + FunDef (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil)))))))))) (Cons (Tuple (Cons 'n' Nil) (Type (Cons 'I' (Cons 'n' (Cons 't' Nil))))) (Cons (Tuple (Cons 'x' (Cons 's' Nil)) (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil)))) @@ -62,18 +62,18 @@ (Cons (CaseAlternative (ConstructorPattern (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons Wildcard (Cons (IdentPattern (Cons 'x' (Cons 's' Nil))) Nil))) (ExpApp (ExpApp (Symbol (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil))))))))))) (ExpApp (ExpApp (Cons '+' Nil) (Cons 'n' Nil)) (BasicValue (BVInt 1)))) (Cons 'x' (Cons 's' Nil)))) - Nil))))) + Nil)))) (# -(fun length ((xs : List a)) : Int - (length_acc 0 xs)) -(fun length_acc ((n : Int) (xs : List a)) : Int - (case xs ( +(fun length ((xs : List a)) : Int : + length_acc 0 xs) +(fun length_acc ((n : Int) (xs : List a)) : Int : + case xs ( (Nil -> n) - (Cons _ xs -> length_acc (+ n 1) xs)))) + (Cons _ xs -> length_acc (+ n 1) xs))) #) -(fun testb ((x : Int) (y : Int)) : Int - (Tuple 37 'a')) -(fun test () : Int - (testb 37 42)) +(fun testb ((x : Int) (y : Int)) : Int : + Tuple 37 'a') +(fun test () : Int : + testb 37 42) diff --git a/snug-clean/src/Snug/Parse.icl b/snug-clean/src/Snug/Parse.icl index 64331c5..9d58f23 100644 --- a/snug-clean/src/Snug/Parse.icl +++ b/snug-clean/src/Snug/Parse.icl @@ -42,7 +42,7 @@ where (pToken (TIdent "fun") *> symbolIdent) (simpleList (parenthesized typedArgument)) (pToken TColon *> type) - simpleOrParenthesizedExpression + (pToken TColon *> expression) simpleConstructorDef = liftM2 ConstructorDef constructorIdent (pure []) constructorDef = liftM2 ConstructorDef constructorIdent (many simpleOrParenthesizedType) -- cgit v1.2.3