fantasyland / fantasy-land

Specification for interoperability of common algebraic structures in JavaScript
MIT License
10.08k stars 373 forks source link

Functors and functions both called `f` can be confusing #289

Closed dmitriz closed 6 years ago

dmitriz commented 6 years ago

In https://github.com/fantasyland/fantasy-land#map-method the letter f denotes a functor:

map :: Functor f => f a ~> (a -> b) -> f b

But in the next line the same f is a function:

u.map(x => f(g(x)))

Would it be less confusing to use different letters perhaps?

davidchambers commented 6 years ago

Suggestions? g(h(x))?

dmitriz commented 6 years ago

@davidchambers

Suggestions? g(h(x))?

It is less confusing, but g and h still look too similar to f. Here the meaning of f is different from anything else. It would be nice to make it look fundamentally different, e.g. as the capital F instead of f, as in the math books.

davidchambers commented 6 years ago

Capitalized identifiers refer to concrete types, such as Boolean in filter :: Filterable f => f a ~> (a -> Boolean) -> f a.

i-am-tom commented 6 years ago

It bears repeating that these identifiers don't have to be single letters; would it be easier if the definition were simply map :: Functor flType => flType a -> (a -> b) -> flType b?

dmitriz commented 6 years ago

Capitalized identifiers refer to concrete types, such as Boolean in filter :: Filterable f => f a ~> (a -> Boolean) -> f a.

Since Boolean is written fully and F an abbreviation, that would still look different.

i-am-tom commented 6 years ago

@dmitriz The point is that, in Haskell, a capital letter always indicates a concrete type, class, family, etc - never a variable. It would be a shame to diverge, imo

dmitriz commented 6 years ago

@i-am-tom

The point is that, in Haskell, a capital letter always indicates a concrete type, class, family, etc - never a variable. It would be a shame to diverge, imo

Haskell suffers from the same confusion - functors and functions are called f. I have never understood why. As if they run out of letters :)

Also both syntax and even operator names (return vs of) are already different in Haskell.

davidchambers commented 6 years ago

In Haskell, types and values live in different namespaces. This allows punning such as Identity :: a -> Identity a, which is very nice in my opinion.

joneshf commented 6 years ago

They live in different namespaces in FL as well.

gabejohnson commented 6 years ago

This looks like a duplicate of #217 to me.

dmitriz commented 6 years ago

@davidchambers

In Haskell, types and values live in different namespaces. This allows punning such as Identity :: a -> Identity a, which is very nice in my opinion.

Do you mean using the same word to mean different things, depending on the context? Does that not expose the code to more bugs due to possible messed up context e.g. by mistake? I always find it harder to read, as it requires additional mental effort to recoginize the context.

dmitriz commented 6 years ago

@gabejohnson

This looks like a duplicate of #217 to me.

True, was long time ago, I forgot it ;)

Which, however, lead to PR with many more suggestions, that was closed by @davidchambers for reasons not related to this issue

joneshf commented 6 years ago

Per @gabejohnson's comment, closing in favor of #217. If there's more to discuss, let's reopen #217 and continue the discussion there. If that's wrong, and this issue is different from #217, let's re-open and continue discussion here.

EDIT: @dmitriz sorry, we were typing at about the same time :). Didn't mean to reply almost immediately after you.

dmitriz commented 6 years ago

@joneshf I will leave it at that, I feel it does create some extra confusion for the newcomers, but if no one feels the need to change it, I'm not going to press it ;)