Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

```Haskell

-- | Flipped version of '<$>'.

infixl 1 <&>

(<&>) :: Functor f => f a -> (a -> b) -> f b

as <&> f = f <$> as

```

"infix", "Functor", and "as" are the only words in this code. Everything else is single letters (thanks math traditions..) and punctuation. What's a <&>? <$>? ::? We've got two different kinds of arrows, => and ->. -- is obviously enough a line comment. At least I know what = means.. give or take it's constant ambiguous meaning between languages of assignment and/or equality testing.

And this isn't even delving into the black arts of defining types, where the really ugly punctuation toolkits get opened.

I don't care whether or not they represent regular functions nor what their calling syntax is. What I care is that the base language has many many dozens of them to remember and then to parse in the wild, and then that authors are encouraged to continue proliferating more of them:

```Haskell

-- What does this 'mouse operator' mean? :thinking_suicide:

(~@@^>) :: Functor f => (a -> b) -> (a -> c -> d) -> (b -> f c) -> a -> f d

```

Credit: Kowainik's Haskell Style Guide https://kowainik.github.io/posts/2019-02-06-style-guide



you're just not familiar with it. like when you ask what "a <&>" means, well this code is literally defining what it means. it means whatever comes after the equals sign

in fact the example you picked is trivially simple even if you dont really know the syntax. all you need to do is not rage out and stop thinking. it's literally saying that "as <&> f" is equal to "f <$> as". so you dont even need to know what <$> is, its extremely straightforward that <&> is just flipping the order of the arguments to <$>

also if you read the type signature then there really arent many possible things this function could do. you start with a Functor a and a function that maps from a to b, and you end up with a Functor b. there's really only one possible implementation of that (applying the function (a -> b) to the a in Functor a)

like im curious, what would you even name these things to make it clearer? it's so abstract in generic in the very concept of it that it's hard to come up with any more specific naming

Functor functor => functor someType -> (someType -> someOtherType) -> functor someOtherType

is that better?


Look, the code comment goes so far as to say that <punctuationA> is a flipped version of <punctuationB> so in this example that part isn't even the part that's not clear to somebody who hasn't memorized all of the language's in-built punctuation (nor new crap invariably invented by libraries).

But what is a <$>? Should one google something like that and hope that Google honors it like a word instead of ignoring it like it usually does punctuation? (In this case Google does appear to honor it as a keyword.. in 9/10 circumstances with punctuation blocks it however does not) Or ask an LLM and get a confidently wrong answer there?

Is it even one piece of punctuation, or two or thee pieces placed adjacent to one another? Like maybe the <> are like parenthesis and the $ is an argument in there.. who knows until you study the nuts and bolts of how this particular language lexes things. (I'm just kidding though.. I get that Haskell would never never be so cruel as to use <> as parenthesis anywhere ;)

Any keyboard bash of punctuation can be defended as understandable once you've memorized all of the symbols and composition rules to parse it. People who code Brainfuck all of the time can read it quite readily, and might even argue that it's overblown that it was ever named "Brainfuck" to begin with.

> Functor functor => functor someType -> (someType -> someOtherType) -> functor someOtherType > is that better?

Moderately, though there remains room for improvement.

Personally I'm able to follow what's happening to the right of the fat arrow because I've cut my teeth on that style of type signature in Elm and Lean. It's taking as first argument a functor over one type ("typeA" might be a still better name), second argument is a function that in turn accepts typeA and emits typeB, and this signature's output is a functor over typeB.

Unfortunately I've mostly forgotten what a functor was after once learning it (IIRC it's an isomorphism in category theory or some kind or another? I can remember what monads are and how to use them in coding, and a monad over a type makes sense to me.. it's basically a tagged type) and in that light the left side of fat arrow being "Functor functor" doesn't clarify much. the lowercase "functor" (or "f") is obviously like a type variable, though probably specifically for functors instead of types. The uppercase one.. I don't know.. says something about the shape of the operator being declared?

In any event, finding a way to make the variable name descriptive without echoing the keyword at the beginning would be helpful, just as in prose we often use synonyms to avoid confusing word re-use.

And finally: bear in mind this isn't primarily a discussion about "I lack exposure to X therefore fill me in on X", but instead about "lots of people lack exposure to X therefore being easier to digest in the first place would have been preferable".


> But what is a <$>? Should one google something like that and hope that Google honors it like a word instead of ignoring it like it usually does punctuation?

No... that's what Hoogle is for. You can literally search by symbol or by type signature, and it's amazing.

Examples

- By symbol: https://hoogle.haskell.org/?hoogle=%3C%26%3E

- By signature: https://hoogle.haskell.org/?hoogle=Functor%20f%20%3D%3E%20f%...


Sure, but that’s more about naming than syntax. You pick whatever names you prefer.

  syntax != vocab


You don't get to pick the names foist upon you by the language or the libraries, though.


You totally can, and many people trivially write their own standard library when they work with Haskell.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: