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

06/17/10 02:06:32 (7 years ago)
benl (IP:



  • Language/Overview/EvaluationOrder

    v2 v3  
    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. 
     6This function: 
     8f a b = f1 (f2 a) (f3 b) 
     11is desugared to: 
     14f a b 
     15 = do   x1 = f2 a 
     16        x2 = f3 b 
     17        f1 x1 x2 
     20where `x1` and `x2` are fresh variables. 
     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. 
     25''Differences to Haskell'': The `do` expression does not perform monadic desugaring, though there is a plan to overload the syntax in the future. 
     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. 
     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.  
     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. 
     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. 
     36To suspend the applications of `f1` and `f3` in the above example we can write: 
     39 f a b  = f1 @ (f2 a) (f3 @ b) 
     42which is equivalent to: 
     45 f a b 
     46  = do  x1 = f2 a 
     47        x2 = suspend1 f3 b 
     48        suspend2 f1 x1 x2