aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2017-03-07 15:50:27 +0100
committerCamil Staps2017-03-07 15:50:27 +0100
commit4ef51410999ebcd12b967ba4228659f57650d956 (patch)
treee68360b980ec11beef52172a27102d282a5f8911
parentAdd .gitignore (diff)
Tuple constructors (resolves #2)
-rw-r--r--README.md11
-rw-r--r--frontend/parse.icl23
2 files changed, 24 insertions, 10 deletions
diff --git a/README.md b/README.md
index 3c02a28..d6dd1a9 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ This is a fork to implement experimental new features.
1\. [Syntactic sugar](#1-syntactic-sugar)
1.1. [Lambda-case](#11-lambda-case)
+1.2. [Tuple constructors](#12-tuple-constructors)
2\. [Syntax changes](#2-syntax-changes)
2.1. [Use of module header keywords](#21-use-of-module-header-keywords)
@@ -50,6 +51,16 @@ LambdaAbstr = ...
| \case of {CaseAltDef}+
```
+### 1.2. Tuple constructors
+
+There are now tuple constructors that can be used curriedly, similar to GHC and
+the way the tuple type could be curried already. For example:
+
+```clean
+import StdFunc
+Start = flip (,) 5 10
+```
+
## 2. Syntax changes
### 2.1. Use of module header keywords
diff --git a/frontend/parse.icl b/frontend/parse.icl
index 95e7b9d..85e3364 100644
--- a/frontend/parse.icl
+++ b/frontend/parse.icl
@@ -3020,18 +3020,9 @@ trySimpleTypeT token attr pState
trySimpleTypeT_after_OpenToken :: !Token !TypeAttribute !ParseState -> (!ParseResult, !AType, !ParseState)
trySimpleTypeT_after_OpenToken CommaToken attr pState
- # (tup_arity, pState) = determine_arity_of_tuple 2 pState
+ # (tup_arity, pState) = determine_arity_of_tuple "tuple type" 2 pState
tuple_symbol = makeTupleTypeSymbol tup_arity 0
= (ParseOk, {at_attribute = attr, at_type = TA tuple_symbol []}, pState)
- where
- determine_arity_of_tuple :: !Int !ParseState -> (!Int, !ParseState)
- determine_arity_of_tuple arity pState
- # (token, pState) = nextToken TypeContext pState
- | CommaToken == token
- = determine_arity_of_tuple (inc arity) pState
- | CloseToken == token
- = (arity, pState)
- = (arity, parseError "tuple type" (Yes token) ")" pState)
trySimpleTypeT_after_OpenToken ArrowToken attr pState
# (token, pState) = nextToken TypeContext pState
| token == CloseToken
@@ -3062,6 +3053,15 @@ trySimpleTypeT_after_OpenToken_and_type CommaToken annot_with_pos atype attr pSt
trySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState
= (ParseFailWithError, atype, parseError "Simple type" (Yes token) "')' or ','" pState)
+determine_arity_of_tuple :: !String !Int !ParseState -> (!Int, !ParseState)
+determine_arity_of_tuple error arity pState
+ # (token, pState) = nextToken TypeContext pState
+ | CommaToken == token
+ = determine_arity_of_tuple error (inc arity) pState
+ | CloseToken == token
+ = (arity, pState)
+ = (arity, parseError error (Yes token) ")" pState)
+
instance try BasicType
where
try IntTypeToken pState = (Yes BT_Int , pState)
@@ -3592,6 +3592,9 @@ trySimpleExpressionT OpenToken pState
CloseToken
#! unit_cons_ident = predefined_idents.[PD_UnitConsSymbol]
-> (True,PE_Ident unit_cons_ident,pState)
+ CommaToken
+ #! (tup_arity, pState) = determine_arity_of_tuple "tuple constructor" 2 pState
+ -> (True, PE_Ident predefined_idents.[GetTupleConsIndex tup_arity], pState)
_
# (args=:[exp:exps], pState) = want_expression_list_t token pState
pState = wantToken FunctionContext "expression list" CloseToken pState