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/string.ts

44 lines
1.4 KiB

import { toNative as $$, L, _, fromNative as __ } from './core';
import { Ord } from './ord';
import { Bool } from './bool';
import { fromNumber as _nn } from './num';
import { toChar as $c, Char, fromChar as _c, cmp as cmpc, eq as eqc } from './char';
import { Cons as ConsL, List, Nil, cmp as cmpl, concat as concatl, eq as eql, ge as gel, gt as gtl, le as lel, lt as ltl } from './list';
export type String = List<Char>;
export const Empty: String
= Nil;
export const Cons: L<(c: Char) => L<(s: String) => String>>
= ConsL;
export const cons: L<(c: Char) => L<(s: String) => String>>
= Cons;
export const concat: L<(l: String) => L<(r: String) => String>>
= concatl;
export const cmp: L<(l: String) => L<(r: String) => Ord>>
= cmpl._(cmpc);
export const lt: L<(l: String) => L<(r: String) => Bool>>
= ltl._(cmpc);
export const le: L<(l: String) => L<(r: String) => Bool>>
= lel._(cmpc);
export const eq: L<(l: String) => L<(r: String) => Bool>>
= eql._(eqc);
export const ge: L<(l: String) => L<(r: String) => Bool>>
= gel._(cmpc);
export const gt: L<(l: String) => L<(r: String) => Bool>>
= gtl._(cmpc);
export const fromString: (xs: string) => String
= xs => xs.length === 0 ? Nil : Cons._(_c(xs[0]))._(new L(() => fromString(xs.slice(1)).value));
export const toString: (xs: String) => string
= xs => $$(xs._(__(''))._(_(x => _(xs => __($c(x) + toString(xs))))));