Skip to content

Commit

Permalink
Merge pull request #16 from ENvironmentSet/0.0.0-alpha.6
Browse files Browse the repository at this point in the history
Merge works
  • Loading branch information
ENvironmentSet authored Aug 3, 2024
2 parents 1250686 + 3575a99 commit 79ac226
Show file tree
Hide file tree
Showing 35 changed files with 12,469 additions and 510 deletions.
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.log
.DS_Store
node_modules
.idea
src
docs
.github
CODE-OF-CONDUCT.md
tsconfig.json
.gitignore
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

Collection of Dependently-typed stuff

> **⚠️WARNING**: This library is not for production, I've used sort of **unstable tricks**.
> **⚠️WARNING**: This library in currently on construction, it will take some time to be ready.
## Documentation is WIP
## Documentation is WIP
12,183 changes: 12,167 additions & 16 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"version": "0.0.0-alpha.5",
"version": "0.0.0-alpha.6",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/welltyped.esm.js",
"typings": "dist/index.d.ts",
"files": [
"dist",
Expand All @@ -13,19 +14,18 @@
"name": "welltyped",
"author": "ENvironmentSet <herryseo1@gmail.com> (https://github.com/ENvironmentSet)",
"description": "Collection of Dependently-typed stuff",
"module": "dist/welltyped.esm.js",
"repository": {
"type": "git",
"url": "git+https://github.com/ENvironmentSet/welltyped.git"
},
"bugs": {
"url": "https://github.com/ENvironmentSet/Acropolis/issues"
"url": "https://github.com/ENvironmentSet/welltyped/issues"
},
"homepage": "https://github.com/ENvironmentSet/Acropolis#readme",
"homepage": "https://github.com/ENvironmentSet/welltyped#readme",
"devDependencies": {
"husky": "^4.2.5",
"tsdx": "^0.13.2",
"tslib": "^1.11.2",
"typescript": "^3.9.2"
"tsdx": "^0.13.3",
"tslib": "^2.3.1",
"typescript": "^4.5.4"
}
}
18 changes: 18 additions & 0 deletions src/Array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TArray, Cons, Concat } from './Promoted/TArray';
import { TType } from './Primitive/TType';

export function cons<type extends TType, tarray extends TArray>(x: type, xs: tarray): Cons<type, tarray> {
return [x, ...xs];
}

export function head<type extends TType>([x]: Cons<type, TArray>): type {
return x;
}

export function tail<tarray extends TArray>([_, ...xs]: Cons<TType, tarray>): tarray {
return xs;
}

export function concat<xs extends TArray, ys extends TArray>(xs: xs, ys: ys): Concat<xs, ys> {
return [...xs, ...ys];
}
12 changes: 12 additions & 0 deletions src/Control/Control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { HKT } from '../Primitive/HKT';
import { TType } from '../Primitive/TType';
import { TBoolean } from '../Promoted/TBoolean'

export type If<condition extends boolean, then, orElse> = condition extends true ? then : orElse;
export interface If_ extends HKT {
params: [TBoolean, TType, TType];
condition: this['params'][0];
then: this['params'][1];
orElse: this['params'][2];
result: If<this['condition'], this['then'], this['orElse']>;
}
22 changes: 22 additions & 0 deletions src/Control/State.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PhantomTypeParameter } from '../Primitive/PhantomTypeParameter';
import { TType } from '../Primitive/TType';
import { Apply, HKT } from '../Primitive/HKT';

type Context<context> = PhantomTypeParameter<'welltyped/state/context', context>;
type Shadow<shadow> = PhantomTypeParameter<'welltyped/state/phantom', shadow>;
type PickContext<state> = state extends Context<infer context> ? context : never;
type PickShadow<shadow> = shadow extends Shadow<infer shadow> ? shadow : never;

export interface Return<a extends TType> extends HKT { //@TODO: Make State strictly typed via kind polymorphism.
params: [TType];
context: this['params'][0];
result: a & Context<this['context']> & Shadow<a>;
}

export interface Bind<state extends HKT, f extends HKT> extends HKT {
params: [TType];
context: this['params'][0];
result: Apply<f, [PickShadow<state>, PickContext<this['context']>]>
}

export type Exec<state extends HKT, s extends TType> = Apply<state, [s]>;
80 changes: 19 additions & 61 deletions src/Function.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,26 @@
import { Length, Reduce, AnyList, Map, Head, Tail, Snoc, Init, Cons, Scan } from './Promoted/List';
import { hnil } from './HList';
import { Z, S } from './Promoted/Nat';
import { Stuck } from './Primitive/Stuck';
import { HKT, Apply } from './Primitive/HKT';
import { DeriveGeneric, UnInitialized } from './Primitive/UnInitialized';
import { Intersection } from './Promoted/Intersection';
import { Flip } from './HKT/Flip';
import { If } from './Promoted/Bool';
import { Head, Length, Tail, TArray } from './Promoted/TArray';
import { Eq } from './Promoted/Eq';
import { Assert } from './Primitive/Assert';

export type AnyFunction = (...args: never) => unknown;
export type TFunction = (...args: never) => unknown;
type ConstraintVariadicFunction<f extends TFunction>
= Eq<Length<Parameters<f>>, number> extends true ? [never] : never;

type FilterByMatch<A, B> = {
base: B;
recursiveStep: If<[Eq<[Head<A>, Head<B>]>, FilterByMatch<Tail<A>, Tail<B>>, Cons<[Head<B>, FilterByMatch<Tail<A>, Tail<B>>]>]>
}[Length<A> extends Z ? 'base' : 'recursiveStep'];
export type Curried<f extends TFunction>
= Length<Parameters<f>> extends 0 ?
ReturnType<f>
: (x: Head<Parameters<f>>) => Curried<(...args: Assert<Tail<Parameters<f>>, TArray>) => ReturnType<f>>;
//@FIXME(Assert): IDK Why typescript can't catch that result of type well if there is variadic element with conditional type.

interface ExtractNArgFunction<functionSignature extends AnyFunction> extends HKT {
result:
this['param'] extends AnyList ?
FilterByMatch<this['param'], Parameters<functionSignature>> extends infer A ?
A extends AnyList ?
(...args: this['param']) => Curried<(...args: A) => ReturnType<functionSignature>>
: Stuck
: Stuck
: Stuck;
function setFunctionLength<f>(f: f, length: number): f {
return Object.defineProperty(f, 'length', { value: length });
}

type Subsequences<list extends AnyList> = Init<Scan<[
Flip<Snoc>,
[],
list
]>>;

interface _Curried extends HKT {
result: this['param'] extends infer f ?
f extends AnyFunction ? {
base: Length<Parameters<f>> extends Z ? ReturnType<f> : f;
recursiveStep:
Reduce<[
Intersection,
unknown,
Map<[
ExtractNArgFunction<f>
,
Subsequences<Parameters<f>>
]>
]>
}[Length<Parameters<f>> extends Z | S<Z> ? 'base' : 'recursiveStep']
: Stuck
: Stuck;
}
type Curried<param = UnInitialized> = DeriveGeneric<_Curried, param>;

export function curry<f extends AnyFunction>(f: f): Curried<f> {
function _curry<applied extends AnyList>(applied: applied): Curried<f> {
//@ts-expect-error @TODO: Type this code
return (...args) => args.length + applied.length < f.length ? _curry(applied.concat(args)) : f(...(applied.concat(args)));
}

return _curry(hnil);
}

export type ElimWithConstraint<constraint extends HKT> = <R>(f: <A>(x: Apply<constraint, A>) => R) => R;
export function makeElimWithConstraint<constraint extends HKT>(): <A>(x: Apply<constraint, A>) => ElimWithConstraint<constraint> {
return x => f => f(x);
//@FIXME: Is there any nature way not to use @ts-ignore?
export function curry
<f extends TFunction, constraint extends ConstraintVariadicFunction<f>>
(f: f): Length<Parameters<f>> extends 0 ? f : Curried<f> {
if (f.length < 2) return f as Length<Parameters<f>> extends 0 ? f : Curried<f>;
//@ts-ignore
else return x => curry(setFunctionLength((...args) => f(x, ...args), f.length - 1));
}
16 changes: 0 additions & 16 deletions src/HKT/Compose.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/HKT/Flip.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/HList.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/Object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TObject, Set, Get } from './Promoted/TObject';
import { TString } from './Promoted/TString';
import { TType } from './Primitive/TType';

export function get<o extends TObject, k extends keyof o>(o: o, k: k): Get<o, k> {
return o[k];
}

export function set<o extends TObject, k extends TString, v extends TType>(o: o, k: k, v: v): Set<o, k, v> {
return { ...o, [k]: v } as Set<o, k, v>;
}
104 changes: 0 additions & 104 deletions src/OpenRecord.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/Operator/Eq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { HKT } from '../Primitive/HKT';
import { TType } from '../Primitive/TType';

export type Eq<a, b> =
(<T>() => T extends a ? never : never) extends (<T>() => T extends b ? never : never) ?
true : false;
export interface Eq_ extends HKT {
params: [TType, TType];
a: this['params'][0];
b: this['params'][1];
result: Eq<this['a'], this['b']>;
}
Loading

0 comments on commit 79ac226

Please sign in to comment.