Comments (7)
This is what I have now. Is this the correct generated version?
// Auto generated from io.soabase.halva.comprehension.ReaderOptionalForFactory by Soabase io.soabase.halva.comprehension.MonadicFor annotation processor
package io.soabase.halva.comprehension;
import io.soabase.halva.any.AnyVal;
import java.lang.SuppressWarnings;
import java.util.function.Supplier;
import javax.annotation.Generated;
@Generated("io.soabase.halva.comprehension.MonadicFor")
public class ReaderOptionalFor<A> {
private final MonadicForImpl<Reader> delegate;
private ReaderOptionalFor(MonadicForImpl<Reader> delegate) {
this.delegate = delegate;
}
public static <A> ReaderOptionalFor<A> start() {
return new ReaderOptionalFor<A>(new MonadicForImpl<Reader>(new ReaderOptionalForFactory()));
}
public <MF_A, MF_B> ReaderOptionalFor<A> forComp(AnyVal<MF_B> any, Supplier<? extends Reader<MF_A, MF_B>> supplier) {
delegate.forComp(any, supplier);
return this;
}
@SuppressWarnings("unchecked")
public <MF_A, MF_B> Reader<MF_A, MF_B> yield(Supplier<MF_B> supplier) {
return delegate.yield(supplier);
}
public <R> ReaderOptionalFor<A> letComp(AnyVal<R> any, Supplier<R> supplier) {
delegate.letComp(any, supplier);
return this;
}
}
from soabase-halva.
Yep that looks right, awesome thanks!
from soabase-halva.
Ah no sorry that was wrong, if needs to look like this: https://github.com/Alex-At-Home/halva-scalaz-examples/blob/master/src/test/java/person/alexp/halva/examples/ReaderOptionalFor2.java
ie if you specify a (single) inner type (and any number of template types) instead of leaving it untyped (eg Optional and A here) then you're declaring that you're composing Monads
from soabase-halva.
Hmm interesting, it appears that now if you have >1 generic type in your monad then you can't use the untyped version, eg
public class OptionalForFactory implements MonadicForWrapper<Optional> {
is fine because Optional only takes one typepublic class ReaderOptionalForFactory<A> implements MonadicForWrapper<Reader<A, Optional>> {
is fine because both types are specifiedpublic class ReaderForFactory implements MonadicForWrapper<Reader> {
now errors
The reason we specified no types was that the "monadic type" can change via the flatMap
/for comprehension, eg Reader<String, Int>
-> flatMap(a -> a.toString())
-> Reader<String, String>
.
So you'd have to do something like:
public class ReaderForFactory<A> implements MonadicForWrapper<Reader<A, ?>> {
- which is a bit nasty because it becomes quite tricky to persuade theflatMap
to compile - the old untyped expression was attractive even though it wasn't super type safe because it was nice and easy to override theflatMap
/map
, vs having to wrestle with Java type inference.- (you don't get any additional type safety after writing the for wrapper)
So I think it should be possible just to revert to the old logic for untyped multi-generic-type monads?
from soabase-halva.
If there is a way if making the `MonadicForWrapper fully type safe then I am all for it :)
eg you could try to do
public class OptionalForFactory<T> implements MonadicForWrapper<Optional<T>> {
public class ReaderForFactory<A, T> implements MonadicForWrapper<Reader<A, T>> {
public class ReaderOptionalForFactory<A, T> implements MonadicForWrapper<Reader<A, Optional<T>>> {
and then the forComp would become (eg):
ReaderForFactory<A, T2> forComp(Any<T2>, Supplier<T2>)
(etc)
I think that will work fine, and it was just more trouble than it was worth in my example code that inspired your annotations, because I wasn't auto generating code or whatever
Or it works fine as is, with the 2 lines commented out from the last commit (I stuck a message in the linked commit) :)
from soabase-halva.
The behavior is now optional. Use @MonadicFor(applyParentTypeParameter = true)
to get the enhanced behavior. This will allow you to choose how the generation is done. Let me know if this solves the issue.
from soabase-halva.
I'm going to close this as the original issue is dealt with. If you want more functionality open another issue.
from soabase-halva.
Related Issues (20)
- More thoughts on pattern matching syntax
- Fix documentation re type aliases HOT 1
- Support type aliases of concrete types, constructor overrides, co-variant returns HOT 4
- TypeAliases - a few more issues/thoughts from using it HOT 3
- Support container types for concrete classes HOT 6
- Support generated values inside of generated classes
- Have simpler Consable<T> interface?
- Should (can?) type aliases also "override" the static members to "fix" the return type HOT 3
- Use enums for case objects HOT 1
- Support command line overrides for Annotation attributes
- Review Type Safety - Pattern/Extraction is currently loosely typed. Make it strongly typed without (hopefully) losing usability HOT 1
- Think about supporting Bean Validation 1.1 annotations on fields HOT 3
- Add debug tools
- Support extracted/multi-assignment
- Add support for dsl-json HOT 2
- CaseClasses that extend interfaces not working properly
- Halva annotation retentions should be RUNTIME HOT 1
- Halva annotations must appear first
- CaseClass mis-generates wildcard types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soabase-halva.