lef*_*out 5 syntax haskell indentation switch-statement
我刚发现这个
foo = case ((), ()) of
( ()
, () ) -> ()
Run Code Online (Sandbox Code Playgroud)
失败了
/tmp/wtmpf-file11080.hs:3:8:
parse error (possibly incorrect indentation or mismatched brackets)
Run Code Online (Sandbox Code Playgroud)
这可以通过缩进模式的第二行来实现
foo = case ((), ()) of
( ()
, () ) -> ()
Run Code Online (Sandbox Code Playgroud)
但这感觉与我平常的风格不一致,特别是在
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
Run Code Online (Sandbox Code Playgroud)
如何重写/格式化以使其看起来最一致?
通过缩进规则,代码
foo = case ((), ()) of
( ()
, () ) -> ()
Run Code Online (Sandbox Code Playgroud)
很沮丧
foo = case ((), ()) of
{ ( ()
; , () ) -> ()
}
Run Code Online (Sandbox Code Playgroud)
这是一个case有两个分支,第一个是语法错误.
我建议使用以下样式:
foo = case ((), ()) of
(( ()
, () )) -> ()
Run Code Online (Sandbox Code Playgroud)
甚至(不是非常优雅)
foo = case ((), ()) of
_@( ()
, () ) -> ()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
94 次 |
| 最近记录: |