Skip to content

Commit 2cf8321

Browse files
authored
Merge pull request #50 from mkantor/number-is
Add `integer.is` and `natural_number.is` to prelude
2 parents 7d0c8f0 + 5718fb0 commit 2cf8321

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/language/semantics/prelude.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ export const prelude: ObjectNode = makeObjectNode({
228228
),
229229
),
230230
),
231+
is: preludeFunction(
232+
['integer', 'is'],
233+
{
234+
parameter: types.something,
235+
return: types.boolean,
236+
},
237+
argument =>
238+
either.makeRight(
239+
typeof argument === 'string' &&
240+
types.integer.isAssignableFrom({
241+
name: '',
242+
kind: 'union',
243+
members: new Set([argument]),
244+
})
245+
? 'true'
246+
: 'false',
247+
),
248+
),
231249
less_than: preludeFunction(
232250
['integer', 'less_than'],
233251
{
@@ -449,6 +467,24 @@ export const prelude: ObjectNode = makeObjectNode({
449467
),
450468
),
451469
),
470+
is: preludeFunction(
471+
['natural_number', 'is'],
472+
{
473+
parameter: types.something,
474+
return: types.boolean,
475+
},
476+
argument =>
477+
either.makeRight(
478+
typeof argument === 'string' &&
479+
types.naturalNumber.isAssignableFrom({
480+
name: '',
481+
kind: 'union',
482+
members: new Set([argument]),
483+
})
484+
? 'true'
485+
: 'false',
486+
),
487+
),
452488
}),
453489

454490
object: makeObjectNode({

0 commit comments

Comments
 (0)