Last active
August 29, 2015 14:02
-
-
Save MLLeKander/ab34d67516446629ef26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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