Hi Egor and Paco, thanks for the response. I'm not...
# arrow
l
Hi Egor and Paco, thanks for the response. I'm not proposing a new Functor for the SetK or change how it behaves, I would like to solve a flaw in the Kotlin language (Not related to Sets at all). I did a poor job explaining myself. The problem: Kotlin doesn't have Higher Order Types. So a signature like this one is not possible:
Copy code
Haskell: fmap :: (a -> b) -> f a -> f b
Kotlin (simplified): TA.map() -> TB ; T extends Iterable
The best we can do is:
Copy code
Haskell: fmap :: (a -> b) -> List a -> List b
Kotlin (simplified): IterableA.map() -> ListB
So we have some odd behaviours like this one:
Copy code
val list = LinkedList<String>().map {  } //This is a List and the implementation is ArrayList o.O. I would like to keep LinkedList
//This is true for any other implementation of List

val a : Map<String, String> = TreeMap()
a.k()
a.map {  } //Now I have LinkedHashMap inside the MapK =|
The solution: Since we have Higher Order Types in Arrow, it would be possible to change the implementation of
map
to:
Copy code
fun <F: ForIterable, A, B> Kind<F, A>.map() -> Kind<F, B>
Since we have a parametrised type as the container, it wouldn't change the implementation of the collection. So a map of a LinkedList would return a LinkedList, not an ArrayList.