Friday, June 14, 2019

Function as Functor in Haskell programming language

I was really confused with the Function as Functor and tried to understand what (->) r really means.

Already many explanations about this but still I could find out what the "fixing" of input type "r" in "(->) r" really means.

     It is really similar to the approach to (Either a) b, where the first type "a" is fixed.
     And we can see that :k Either is same as :k (->), both of them are "kind" of *-> * -> * .
     So we have to fix them to have the signature like *-> *, e.g., (->) Int or Either Int has.

     But what does the fix of type mean?
     To me, if we say fix the input parameter type of the function, e.g., "(-) r", it means we don't need to bother to handle mapping over "r",
     but only focus on mapping over of the mapping over of type of result, "a" in "(->) r a", which in turn means we have to map it to "(->) r b".
     You can see "r" is the same , (meaning fixed), above, but the result type changes from "a" to "b".

I will be really happy if I can help somebody to have a deeper understanding, though I am not using academic terms in Haskell.

No comments:

Post a Comment