Lambda calculus-like library written in TypeScript.
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.
 
 
jlc/src/bool.ts

33 lines
962 B

import { toNative as $n, L, P, _, fromNative as _n } from './core';
export type Bool = L<<T extends P>(t: T) => L<(f: T) => T>>;
export const True: Bool
= _(t => _(_f => t)) as Bool;
export const False: Bool
= _(_t => _(f => f));
export const iif: L<<T extends P>(b: Bool) => L<(t: T) => L<(f: T) => T>>>
= _(b => _(t => _(f => b._(t)._(f))));
export const eq: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(r)._(not._(r))))
export const not: L<(b: Bool) => Bool>
= _(b => b._(False)._(True));
export const and: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(r)._(False)));
export const or: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(True)._(r)));
export const xor: L<(l: Bool) => L<(r: Bool) => Bool>>
= _(l => _(r => l._(not._(r))._(r)));
export const fromBoolean: (b: boolean) => Bool
= b => b ? True : False;
export const toBoolean: (b: Bool) => boolean
= b => $n(b._(_n(true))._(_n(false)));