Hacker News new | ask | show | jobs
by moomin 350 days ago
Let’s just say that if you wanted to understand lenses, this is not where you should start; and if you wanted to move to more advanced scenarios, I wouldn’t start here either.
3 comments

A first good step is getting rid of Haskell's obscure and impenetrable syntax, and checking implementations that would be more readable.

Kotlin's Arrow library hits a good middle ground between FP wizardry and readability, and their documentation on lenses are understandable for the average person: https://arrow-kt.io/learn/immutable-data/lens/ / https://arrow-kt.io/learn/immutable-data/intro/

Arrow is how I went from minimal FP to bloody good at it. The Arrow devs are also very giving with their time, and we still interact occasionally online even though I've moved on to Unison for the most part.
> Haskell's obscure and impenetrable syntax

Uhhh... Haskell syntax is simpler than python's or javascript's. It's neither obscure nor impenetrable, but it sounds like it's different than what you're used to.

This is such low hanging bait that I'm not even interested in interacting further with it than: Haskell's syntax is obscure and impenetrable for the vast majority of software engineers because it was designed by FP nerds with zero interest in ergonomics.

It doesn't make it a bad syntax. It is, however, objectively terrible for anyone unfamiliar with it.

Syntax is inherent to the language, and what you’re talking about says more about people than it says about any intrinsic property of the language.

It’s not bait. Call me pedantic if you want, but I think words have meaning.

Haskell has enough punctuation to make Larry Wall blush
They’re just regular functions, but infix.
```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?

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

  syntax != vocab
Being different to what users of ~all top-20 languages are used to is a great way to be obscure and somewhat impenetrable.
where would you start?
What a great read! I had never encountered or thought about prisms before, but now it I see how useful they could be.

Thank you for sharing

Assuming you've got experience with Javascript, read the "Motivation" section on the monocle-ts website:

https://gcanti.github.io/monocle-ts/

Optics by Example by Chris Penner is good. https://leanpub.com/optics-by-example/
Great exercise driven course is: https://github.com/system-f/lets-lens