Created
April 3, 2022 14:58
-
-
Save fogfish/df0a3d58153b974dd83e56330481973f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HKT<F, A> {} | |
interface Functor<F> { | |
map<A, B>(f: (a: A) => B, fa: HKT<F, A>): HKT<F, B> | |
} | |
type Seq<A> = HKT<'Seq', A> | |
type Abc<A> = HKT<'Abc', A> | |
type seq<A> = Array<A> | |
const seqMap = <A, B>(f: (a: A) => B, fa: seq<A>): seq<B> => fa.map(f) | |
const inj = <A>(a: seq<A>): Seq<A> => ((a as any) as Seq<A>) | |
const prj = <A>(a: Seq<A>): seq<A> => ((a as any) as seq<A>) | |
const map = <A, B>(f: (a: A) => B, fa: Seq<A>): Seq<B> => | |
inj(seqMap(f, prj(fa))) | |
const double = <F, A>(fa: HKT<F, A>, f: Functor<F>): HKT<F, [A, A]> => | |
f.map((a: A) => [a, a], fa) | |
const x: seq<number> = [ 1, 2, 3, 4, 5 ] | |
// Here is a bug Seq<[number, number]> != Seq<number> | |
const y: Seq<number> = double<'Seq', number>(x, {map}) | |
console.log(y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment