Skip to content

Instantly share code, notes, and snippets.

@MLLeKander
Last active August 29, 2015 14:02
Show Gist options
  • Save MLLeKander/ab34d67516446629ef26 to your computer and use it in GitHub Desktop.
Save MLLeKander/ab34d67516446629ef26 to your computer and use it in GitHub Desktop.
Functor.java:8: error: unexpected type
public <B> F<B> fmap(Function<A, B> f);
^
required: class
found: type parameter F
where F is a type-variable:
F extends Object declared in interface Functor
1 error
interface Function<A, B> {
public B call(A arg);
}
interface Functor<F, A> {
public <B> F<B> fmap(Function<A, B> f);
}
class List<A> implements Functor<List, A> {
private ArrayList<A> lst = new ArrayList<A>();
public <B> List<B> fmap(Function<A, B> f) {
List<B> out = new List<B>();
for (A tmp : this.lst) {
out.lst.add(f.call(tmp));
}
return out;
}
}
// List<Integer> foo = new List<Integer>();
// foo.lst.add(1);
// Function<Integer, String> toString = new Function<Integer, String>() {
// public String call(A arg) { return arg.toString(); }
// }
// List<String> bar = foo.fmap(toString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment