Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Existential Wrapper #43

Open
theNerd247 opened this issue Jan 28, 2020 · 1 comment
Open

Implementing Existential Wrapper #43

theNerd247 opened this issue Jan 28, 2020 · 1 comment

Comments

@theNerd247
Copy link

I'm trying to write a small library to make it easier to create types that are existentially quantified. I'm using the idea of a type interface F<A> { foo : a, ext : exists E. E } (pseudocode) can be implemented as interface Fe<A,E> { foo : a, ext : E } and type F<A> = <R>(cont : <E>(x : Fe<A,E>) => R) => R. My current implementation can be found here: https://github.com/theNerd247/tsfreeapp/blob/master/existential.ts

liftExt compiles just fine. However mapExt which is supposed to make lifting functions that modify the underlying containers of existentially quantified types easier. However I get the following compiler error and I'm not sure where to start on fixing this any ideas?

existential.ts:34:3 - error TS2322: Type 'Existential2<"Either", unknown>' is not assignable to type 'Existential<F>'.
  Types of property 'runExt' are incompatible.
    Type '<R>(cont: <E>(t: Either<unknown, E>) => R) => R' is not assignable to type '<R>(cont: <E>(t: Kind<F, E>) => R) => R'.
      Types of parameters 'cont' and 'cont' are incompatible.
        Types of parameters 't' and 't' are incompatible.
          Type 'Either<unknown, E>' is not assignable to type 'Kind<F, unknown>'.
            Type 'Left<unknown>' is not assignable to type 'Kind<F, unknown>'.

34   return liftExt(x.runExt(f))
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~

existential.ts:34:27 - error TS2345: Argument of type '<E>(a: Kind<F, E>) => Kind<F, E>' is not assignable to parameter of type '<E>(t: Kind<F, E>) => Kind<F, unknown>'.
  Type 'Kind<F, E>' is not assignable to type 'Kind<F, unknown>'.
    Type 'URItoKind<E>[F]' is not assignable to type 'URItoKind<unknown>[F]'.
      Type 'URItoKind<E>' is not assignable to type 'URItoKind<unknown>'.
        Types of property 'Eq' are incompatible.
          Type 'Eq<E>' is not assignable to type 'Eq<unknown>'.
            Type 'unknown' is not assignable to type 'E'.
              Type 'URItoKind<E>[F]' is not assignable to type '(Eq<unknown> & Ord<unknown> & None) | (Eq<unknown> & Ord<unknown> & Some<unknown>)'.
                Type 'None | Eq<E> | Ord<E> | Some<E>' is not assignable to type '(Eq<unknown> & Ord<unknown> & None) | (Eq<unknown> & Ord<unknown> & Some<unknown>)'.
                  Type 'None' is not assignable to type '(Eq<unknown> & Ord<unknown> & None) | (Eq<unknown> & Ord<unknown> & Some<unknown>)'.
                    Type 'None' is not assignable to type 'Eq<unknown> & Ord<unknown> & None'.
                      Type 'None' is not assignable to type 'Eq<unknown>'.
                        Type 'URItoKind<E>[F]' is not assignable to type 'Eq<unknown> & Ord<unknown> & Some<unknown>'.
                          Type 'None | Eq<E> | Ord<E> | Some<E>' is not assignable to type 'Eq<unknown> & Ord<unknown> & Some<unknown>'.
                            Type 'None' is not assignable to type 'Eq<unknown> & Ord<unknown> & Some<unknown>'.
                              Property 'equals' is missing in type 'None' but required in type 'Eq<unknown>'.
                                Type 'URItoKind<E>[F]' is not assignable to type 'Eq<unknown>'.
                                  Type 'None | Eq<E> | Ord<E> | Some<E>' is not assignable to type 'Eq<unknown>'.
                                    Property 'equals' is missing in type 'None' but required in type 'Eq<unknown>'.

34   return liftExt(x.runExt(f))
@theNerd247
Copy link
Author

After playing with this a bit more I've noticed that compiling works if all other source files are commented out except existential.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant