3 ms·
> `a -> b -> f a -> f b` (a -> b) -> F a -> F b; the parentheses are critical. I don't fully disagree with your point, but if you're going to emphasize rigor a
by Twisol 5y ago
> `a -> b -> f a -> f b`
(a -> b) -> F a -> F b; the parentheses are critical. I don't fully disagree with your point, but if you're going to emphasize rigor and definitions, it would be wise to make sure you're not setting people on the fence up for mistakes akin to those in the original post.
(You also called it `F` and then used it as `f`.)
- Littlebigo 5y agoTo add, I suspect that the Haskell type notation is not intuitive to people not familiar with it. For anyone wondering, (a -> b) -> f a -> f b means "A function taking a function from one type to another "(a -> b)" and a functor applied with one type "(f a)" and returns a functor applied with another type "(f b)".
- Twisol 5y agoI do think familiarity plays a big role. I find the Haskell syntax much more pleasant than Java, even though I'm perfectly familiar with both. The equivalent signature in Java (if we could abstract over type functions) would be: interface Functor<F<_>> { <A, B> Function<F<A>, F<B>> map(Function<A, B> f); } You'll find very similar in Scala's `cats`, up to some currying and reordering. [0] [0] https://typelevel.org/cats/typeclasses/functor.html https://typelevel.org/cats/typeclasses/functor.html
- Littlebigo 5y agoI absolutely agree, I was just adding the explanation for anyone unfamiliar with the syntax.
- Twisol 5y agoAnd I was building on yours :) I hope you didn't mind.