Skip to content

Commit 4c31df6

Browse files
authored
Merge pull request #3 from mkantor/numbers
Add `natural_number` and `integer` types & prelude modules
2 parents c5727b5 + 5da3490 commit 4c31df6

File tree

7 files changed

+386
-114
lines changed

7 files changed

+386
-114
lines changed

src/end-to-end.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,25 @@ testCases(endToEnd, code => code)('end-to-end tests', [
191191
assert.deepEqual(typeof output.value.value, 'string')
192192
},
193193
],
194+
[`:natural_number.add(1)(1)`, either.makeRight('2')],
195+
[
196+
`:natural_number.add(one)(juan)`,
197+
output => {
198+
assert(either.isLeft(output))
199+
},
200+
],
201+
[`:integer.add(42)(-1)`, either.makeRight('41')],
202+
[`:integer.subtract(-1)(-1)`, either.makeRight('0')],
203+
[`:integer.subtract(1)(2)`, either.makeRight('1')],
204+
[
205+
`:object.lookup(output)({
206+
add_one: :integer.add(1)
207+
less_than_three: :integer.less_than(3)
208+
output: :less_than_three(:add_one(1))
209+
})`,
210+
either.makeRight({
211+
tag: 'some',
212+
value: 'true',
213+
}),
214+
],
194215
])

src/language/compiling/semantics/expressions/lookup-expression.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
type ExpressionContext,
1111
type KeywordHandler,
1212
} from '../../../semantics/expression-elaboration.js'
13-
import { stringifyKeyPathForEndUser } from '../../../semantics/key-path.js'
13+
import {
14+
keyPathToMolecule,
15+
stringifyKeyPathForEndUser,
16+
} from '../../../semantics/key-path.js'
1417
import {
1518
isObjectNode,
1619
makeObjectNode,
@@ -52,11 +55,7 @@ export const readLookupExpression = (
5255
} else {
5356
const canonicalizedQuery =
5457
typeof query === 'string'
55-
? makeObjectNode(
56-
Object.fromEntries(
57-
query.split('.').map((key, index) => [index, key]),
58-
),
59-
)
58+
? makeObjectNode(keyPathToMolecule(query.split('.')))
6059
: query
6160

6261
return either.map(
@@ -212,11 +211,7 @@ const lookup = ({
212211
return either.makeRight(
213212
option.makeSome(
214213
makeLookupExpression(
215-
makeObjectNode(
216-
Object.fromEntries(
217-
relativePath.map((key, index) => [index, key]),
218-
),
219-
),
214+
makeObjectNode(keyPathToMolecule(relativePath)),
220215
),
221216
),
222217
)

0 commit comments

Comments
 (0)