Nested case statements in SML

强颜欢笑 提交于 2019-12-04 23:00:44

No. The syntactic rules in the Definition of Standard ML state that the match arms of a case expression attempt to maximally consume potential clauses. And since there's no "end case" or similar marker in the language, the parser will merrily eat each of the "| pat => exp" clauses that you feed it until it sees something that terminates a list of match clauses.

The answer is "(" and ")". My example:

case e1 of                   
   p1 => ( case e11 of         
              NONE => expr11
              | SOME v => expr12 v )
   | p2 => ( case e21 of         
                NONE => expr21
                | SOME v => expr22 v )

This really works! Cool :) You can try it too.

Plain and short answer: no. But what's wrong with parentheses?

(Of course, you can also bracket in other ways, e.g. with a 'let', or by factoring into auxiliary functions, but parentheses are the canonical solution.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!