我才发现这个
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/