gpt4 book ai didi

haskell - 为什么在没有额外缩进的情况下换行大小写匹配会出现语法错误,以及推荐的解决方法是什么?

转载 作者:行者123 更新时间:2023-12-04 17:44:23 25 4
gpt4 key购买 nike

我才发现这个

foo = case ((), ()) of
( ()
, () ) -> ()

失败
/tmp/wtmpf-file11080.hs:3:8:
parse error (possibly incorrect indentation or mismatched brackets)

这可以通过缩进模式的第二行来实现
foo = case ((), ()) of
( ()
, () ) -> ()

但这感觉与我平时的风格不一致,尤其是在
bar = case ( some lengthy :: Complicated typed expression
, another also lengthy :: Expression with (Other types) ) of
( Complicated (Pattern match) to (unwrap)
, Expression that's (Again not so short) ) -> the Rest of my Code

应如何重写/格式化上述内容以使其看起来最一致?

最佳答案

indentation rules , 编码

foo = case ((), ()) of
( ()
, () ) -> ()

脱糖为
foo = case ((), ()) of
{ ( ()
; , () ) -> ()
}

这是一个 case有两个分支,第一个是语法错误。

我会推荐以下样式:
foo = case ((), ()) of
(( ()
, () )) -> ()

甚至(虽然不是特别优雅)
foo = case ((), ()) of
_@( ()
, () ) -> ()

关于haskell - 为什么在没有额外缩进的情况下换行大小写匹配会出现语法错误,以及推荐的解决方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com