Elm 语法,在不使用临时变量的情况下通过管道转发匹配案例

Elm Syntax, Pipe forward a match case without using temp variable

与上述问题类似,有没有一种方法可以在不使用临时变量或 lambda 的情况下将变量通过管道转发到匹配案例?

想法:

let temp =
    x 
    |> Function1
    |> Function2
    // ........ Many functions later.
    |> FunctionN
in

result =
    case temp of
        Case1 -> "Output 1"
        Case2 -> "Output 2"
        _ -> "Other Output"

我希望实现以下目标:

result =
    x 
    |> Function1
    |> Function2
    // ........ Many functions later.
    |> FunctionN
    |> case of     // Syntax Error! Should use "case temp of" 
        Case1 -> "Output 1"
        Case2 -> "Output 2"
        _ -> "Other Output"

我可以使用 lambda 函数,但我仍然 "naming" 临时变量。

result =
    x 
    |> Function1
    |> Function2
    // ........ Many functions later.
    |> FunctionN
    |> \temp -> case temp of      
        Case1 -> "Output 1"
        Case2 -> "Output 2"
        _ -> "Other Output"

在 Elm 语法中有没有办法将临时变量设为 "get rid"?谢谢

不,Elm 没有那个能力。

像 Haskell 这样的其他语言通过 LambdaCase 扩展允许类似的东西,但 Elm 倾向于避免用太多的方式来表达同一件事,而宁愿保持语法简单。

issue has been raised before,Elm 的作者拒绝了该提案并发表了以下评论:

More generally though, the focus right now is not on growing the syntax of Elm. (We're actually dropping stuff more often.) If something can be expressed in Elm already, I'm not hugely interested in providing alternate ways to express it. In this case, I think we would be adding syntax to make things less regular and harder to read.