Domanda

Having something like foo(bar1(), bar2()) can I be sure in SML that it will always evaluate bar1() first and after bar2()?

È stato utile?

Soluzione

Yes. Strictly speaking you have a function which is applied to a tuple. Fields of a tuple are evaluated from left to right so bar1() will be evaluated before bar2(). See "The Definition of Standard ML (Revised)" by Milner, Tofte, Harper and MacQueen page 41.

Note that if foo is actually an expression that could have side-effects or raise an exception it will be evaluated before its argument and therefore before either bar1() or bar2(). This particularly has implications with curried applications.

foo (bar1()) (bar2())

Will evaluate first bar1() then foo(bar1value) before evaluating bar2().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top