Dzoukr / Dapper.FSharp

Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL, PostgreSQL, and SQLite
MIT License
374 stars 35 forks source link

Semantic inconsistency of `+` / `*` for And / Or operators #37

Closed pkese closed 3 years ago

pkese commented 3 years ago

There's this weird operator assignment of (+) -> and and (*) -> or for Select expressions.

The problem is that this is the exact opposite of what one would normally semantically expect these operators to mean...

For example in F# we have Sum and Product types where Sum type (discriminate union) means an OR (one-of given options) and Product type (record) means an AND (all attributes in a type are present).

Similarly it is inconsistent with operator precedence: A or B and C expectedly evaluates to A or (B and C) where as A * B + C in mathematical semantics evaluates to (A * B) + C.

This makes the code really difficult to reason about for people not familiar with this Dapper.FSharp exception.

It's hard to change the meaning of the operators now, as it would break existing code,
but maybe we could add some other alternative operators (&&) / (||) or (&&&) / (|||) or something alike to improve the meaning and understanding.

Dzoukr commented 3 years ago

Hi @pkese, it has been already discussed in #7. The reason behind this (as explained in the issue) is that I took the initial meaning of WHERE as filters (example: https://github.com/CompositionalIT/kibalta/blob/master/src/Kibalta.fs#L57-L60).

You are right, it's too late for change and won't be changed even in the major version. The risk is too high.

However, we have now LINQ API (https://github.com/Dzoukr/Dapper.FSharp#linq-api) where you can use traditional operators.

Thanks anyway and have a great day!