Changes between Version 2 and Version 3 of Language/Overview/EvaluationOrder

Show
Ignore:
Timestamp:
06/17/10 02:06:32 (5 years ago)
Author:
benl (IP: 129.94.242.38)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language/Overview/EvaluationOrder

    v2 v3  
    22 
    33= Evaluation Order = 
     4Disciple uses a strict/call-by-value evaluation order, where compound expressions are evaluated from left to right in data-dependency order. 
     5 
     6This function: 
     7{{{ 
     8f a b = f1 (f2 a) (f3 b) 
     9}}} 
     10 
     11is desugared to: 
     12 
     13{{{ 
     14f a b 
     15 = do   x1 = f2 a 
     16        x2 = f3 b 
     17        f1 x1 x2 
     18}}} 
     19 
     20where `x1` and `x2` are fresh variables. 
     21 
     22== do expressions == 
     23Disciple `do` expressions contain a sequence of bindings and statements, and must end with a statement. These elements are evaluated in turn, from top to bottom. Bindings may not be mutually recursive. The final statement is taken as the value of the entire expression. 
     24 
     25''Differences to Haskell'': The `do` expression does not perform monadic desugaring, though there is a plan to overload the syntax in the future. 
     26 
     27== Introduction of laziness == 
     28Although strict evaluation is the default, any function application may be suspended with the `@` operator, so long as the application does not cause visible side effects. The attempted suspension of an application with visible side effects will result in a compile-time type error. 
     29 
     30The expression `f @ x` (read as: `f` suspend `x`) creates a thunk containing the function `f` and its argument `x`. When the value of this thunk is demanded at runtime, the function will be applied to its argument, yielding the result.  
     31 
     32If a value is not suspended it is called ''direct''. Both ''direct'' and ''lazy'' objects have the same type, are first class and interchangable. The forcing of thunks is transparent and does not require extra code in the source program. 
     33 
     34The suspension operator `@` accepts a variable number of arguments. Uses of `@` map onto a set of primitive `suspend` functions, which can also be used if desired. 
     35 
     36To suspend the applications of `f1` and `f3` in the above example we can write: 
     37 
     38{{{ 
     39 f a b  = f1 @ (f2 a) (f3 @ b) 
     40}}} 
     41 
     42which is equivalent to: 
     43 
     44{{{ 
     45 f a b 
     46  = do  x1 = f2 a 
     47        x2 = suspend1 f3 b 
     48        suspend2 f1 x1 x2 
     49}}}