Custom Ignore operator override ";"

Hello guys,

when showing F# to C#/js people i always have to explain why we don’t use “;” but instead |> ignore.

wouldn’t make sense to have a feature to override the “;” OCaml operator (maybe specifying a compiler flag?) . This would make F# come looks much simpler to them!

or as for Custom post-fix op ? - or maybe there is already some related issue?

Thanks a lot,
have a great weekend!

1 Like

I find |> ignore to be a bit dangerous. It is a compiler workaround to reduce typesafety. I don’t understand why any experienced F# developer would advocate for its usage.

It’s good to be explicit that you are ignoring something, because often accidentally ignoring something is the cause of a bug. Semicolon already has a meaning in F# so it would be a bad idea to give it a new additional meaning.

ignore can also be dangerous. Imagine you have the code myFunc a |> ignore, and then you add a new parameter to myFunc. In some parts of the codebase this would cause type errors for you to fix, but in this example there would be no type error and the function would not even run! I have actually seen this happen before and it caused a bug in production. So now I add a type parameter to ignore to be even more explicit and safe: myFunc a |> ignore<int>.

Rather than trying to hide ignore from people, explain to them that it is a valuable thing, especially if used with a type parameter (for curried functions at least, there is less danger after a method call). If your code is using it all the time, it’s probably the sign of a larger problem that can be refactored away. Can you give any specific examples?

1 Like

Very interesting! I was not aware that ignore can be parameterized. I’ve also seen bugs due to ignore usage that really should have been picked up by the compiler.