You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The design does not distinguish functions and methods. For example, users would add L name prefixes on list operating traits for distinction. It results in C-style naming.
I have an alternative approach that enables us to write methods in impl {} block. We can instead move the first argument to the generic list. The additional benefic is that we can define constant-valued functions.
impl<...> Function<Arg1,Arg2, ...>for(){typeOuput = ...;}implConstFn for (){typeOutput = U3;// from typenum}impl<...> Calling<Arg1,Arg2, ...>for()where():Function<Arg1, ...>// trait bound{typeOutput = <()asFunction<Arg1, ...>>::Output;}
While for methods, the self is regarded as operands.
We can make it further. The Compute* traits are generalized into maps like that is done in my type-freak (code). It enables the function passing arguments. For example, List::map.
pubtraitMap<Inputs>{typeOutput;}// type operating trait from usertraitCompute<Arg1, ...>{}implCompute<Arg1, ...>for(){typeOutput = ...;}// derivedstructComputeMap;impl<...> Map<(Arg1, ...)>forComputeMap{typeOutput = <()asCompute<Arg1, ...>>::Output;}// now we have "callbacks"traitCalling<T,F:Map>{}impl<T,F:Map>Calling<T,F>for(){typeOutput = <FasMap<T1,T2,T3, ...>>::Output;// T1, T2, T3 arguments are derived from T}
The text was updated successfully, but these errors were encountered:
These are great observations. I like the idea of allowing direct impl blocks.
I've been thinking about how to implement higher-order operators like map. This isn't the same, but I think related to implementing polymorphic operators. For example, TIf. Right now I just hackily monomorphize the trait for a set of known types. But ideally you could do something like
The crucial part is that whenever we pass something callable to generic places of a type operator, the callable thing must be a type. The Func trait delegates the type-level computation to a type.
Apart from that, using types that implement Func maybe an alternative building blocks than using trait + impl blocks. I tried it once and got stuck in the issue that the compiler failed to expand recursive traits. You can see the old compiler issue rust-lang/rust#64917.
I noticed tyrade treats the first argument specially when translating function arguments.
The design does not distinguish functions and methods. For example, users would add
L
name prefixes on list operating traits for distinction. It results in C-style naming.I have an alternative approach that enables us to write methods in
impl {}
block. We can instead move the first argument to the generic list. The additional benefic is that we can define constant-valued functions.While for methods, the
self
is regarded as operands.We can make it further. The
Compute*
traits are generalized into maps like that is done in my type-freak (code). It enables the function passing arguments. For example,List::map
.The text was updated successfully, but these errors were encountered: