F# で `a == 1 && a == 2 && a == 3` と `2 + 2 == 5`

もう誰かやってるかもしれない。 記事にネタがなくて困っていたので許して。

a == 1 && a == 2 && a == 3

https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever-evaluate-to-true

let (&&) _ _ = true

警告されるが

warning FS0086: The '&&' operator should not normally be redefined. Consider using a different operator name

実行可能(以下>;;がついた部分はfsharp interactive)

> let a = 1;;            
val a : int = 1

> a = 1 && a = 2 && a = 3;;
val it : bool = true

2 + 2 == 5

加算は警告なし。

let (+) _ _ = 5
> 2 + 2 = 5;;
val it : bool = true

=だと

let (=) _ _ = 5

警告あり

warning FS0086: The '=' operator should not normally be redefined. To define equality semantics for a type, override the 'Object.Equals' member in the definition of that type.

番外編

let (+) _ _ = "ミソスープ"
1 + 1 |> printfn "%A"

あるいは、パイプライン演算子をミソスープ出力器にする。

let (|>) _ _ = printfn "ミソスープ"
1 + 1 |> printfn "%A"

???「ところで、printfnをミソスープにしてもかまわんのだろう?」

let printfn _ _ = printfn "ミソスープ"
1 + 1 |> printfn "%A"

???「ミソスープだけを作る機械かよ!?」