ChrisMarinos/FSharpKoans

HowThePipeOperatorIsDefined

KingKnecht opened this issue · 5 comments

Would be nice to tell newbies, that F# will make an Infix-operator out of (|>). I was thinking ~30min about the black magic that is going on with the given definition:

let (|>) x f =
      f x

How can x (the list in the example) ever be on the left side of the function |>?

Hmmm, that's a good point. On one hand, I think it's actually great that you spent 30 minutes thinking about the the black magic since the goal of the koans is to spur that sort of thinking. However, I can also see where it might feel like you're lacking the information to tie all the pieces together.

I'm good with adding a note about the infix if you think it would be helpful. However, I'm curious- did the 30 minutes feel more like you were wrapping your head around a new concept, or did it more feel like you were cheated when you figured out the infix part?

Because I already read about currying I read about that again, in hope this would solve the problem. But no, couldn't see how that could help me. Then I googled operators, because the title of the koan is "HowThePipeOperatorIsDefined". Didn't want to google Pipe directly .Then I stumbled upon infix operators. Tataa, there it was. Gave me mixed feelings. Happy to understand why it works, a bit angry because it's trivial if you know about the special behavior.
I think most newbies will not even recognize the miracle. They see x and f get reversed, oh cool, that explains it. But if you really think about it, it explains nothing.

I think (custom) infix-operators are a big thing in F# and worth to be mentioned in the koan. How to force people to recognize the problem, I don't know. Maybe a koan about (+)? Used as infix and prefix operator?

Thinking more about it: The definition of the pipe-operator given in the example is not the point why it works. If the koan should explain why it works, the infix-stuff is mandatory.

@KingKnecht can you elaborate a short helpful note, explaining it to you in the way you understand it now? If yes - don't hesitate to make a PR or write a comment.

Just ran through the Koans myself and didn't even clock the infix/prefix definition part. Went back and looked after reading this issue.

We could probably create an AboutOperators.fs because people from outside of the dotnet ecosystem might not be aware that you can override or implement your own operators, which is useful to know with F# as frameworks like Suave have their own operators like >=>.