You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
956 B
34 lines
956 B
import { L, _, id } from './core';
|
|
import { iif } from './bool';
|
|
import { Num, Succ, Zero, fromNumber as _n, eq } from './num';
|
|
|
|
export type Byte = Num;
|
|
|
|
export const x00: Byte
|
|
= Zero;
|
|
|
|
export const xFF: Num
|
|
= _n(255);
|
|
|
|
export const Inc: L<(p: Byte) => Byte>
|
|
= _(p => iif._(eq._(xFF)._(p))._(x00)._(Succ._(p)));
|
|
|
|
export { ifz, cmp, lt, le, eq, ge, gt, even, odd, div, mod, show, toNumber } from './num';
|
|
|
|
export const inc: L<(n: Byte) => Byte>
|
|
= Inc;
|
|
|
|
export const dec: L<(n: Byte) => Byte>
|
|
= _(n => n._(xFF)._(id));
|
|
|
|
export const sum: L<(l: Byte) => L<(r: Byte) => Byte>>
|
|
= _(l => _(r => r._(l)._(_(pr => sum._(inc._(l))._(pr)))));
|
|
|
|
export const sub: L<(l: Byte) => L<(r: Byte) => Byte>>
|
|
= _(l => _(r => r._(l)._(_(pr => sub._(dec._(l))._(pr)))));
|
|
|
|
export const mul: L<(l: Byte) => L<(r: Byte) => Byte>>
|
|
= _(l => _(r => l._(x00)._(_(pl => sum._(r)._(mul._(pl)._(r))))));
|
|
|
|
export const fromNumber: (n: number) => Byte
|
|
= n => _n(n % 256);
|
|
|