This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
Compose generic functions #7291
Milestone
Comments
Hi, here's a much more correct code example for what you're trying to do, which currently passes the typechecker: <T> => F<G<T>>(T) compose<F,G>
(<T> => F<T>(T) f, <T> => G<T>(T) g)
given F<T> given G<T>
=> <T>(T t) => f(g(t));
shared void test() {
T() lazy<T>(T t) => () => t;
[T] singleton<T>(T t) => [t];
value lazySingleton = compose<<T>=>T(),<T>=>[T]>(lazy, singleton);
[Integer]() int = lazySingleton(4);
[String]() str = lazySingleton("");
} Note, however, that:
|
OK, so this runs correctly: <T> => F<G<T>>(T) compose<F,G>
(<T> => F<T>(T) f, <T> => G<T>(T) g)
given F<T> given G<T>
=> <T>(T t) => f(g(t));
shared void test() {
T() lazy<T>(T t) => () => t;
[T] singleton<T>(T t) => [t];
alias Lazy<T> => T();
alias Sing<T> => [T];
value lazySingleton = compose<Lazy,Sing>(lazy, singleton);
[Integer]() int = lazySingleton(4);
[String]() str = lazySingleton("hello");
print(int);
print(str);
print(int());
print(str());
} Apparently there's a problem with anonymous type functions in type argument lists. I'll open an issue. |
Closing, after opening #7354. |
gavinking
added a commit
that referenced
this issue
Apr 17, 2018
gavinking
added a commit
that referenced
this issue
Apr 17, 2018
Both of these problems are now fixed! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Consider the general category of generic functions that take a single parameter of any type and return some result. I need to be able to compose type functions of this sort in a way that preserves the combined return type. Here is an example of the type of composition that I am talking about:
Here is an example that does not work (legal Ceylon, but Nothing inferred for the generic types):
I am guessing that this example does not work because the precise types of FRet and GRet can't be known until combineInner is called, and the type system apparently can't infer or can't represent some sort of parameterized types for them.
Is it possible to define such a function in Ceylon? If not, would any upcoming features like #3860 help? Thanks!
The text was updated successfully, but these errors were encountered: