Personal tools


From HaskellWiki

Jump to: navigation, search

1 Evaluation Order

Disciple uses a strict/call-by-value evaluation order, where compound expressions are evaluated from left to right in data-dependency order.

This function:

f a b = f1 (f2 a) (f3 b)

is desugared to:

f a b
 = do   x1 = f2 a
        x2 = f3 b
        f1 x1 x2
are fresh variables.

2 do expressions

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. Differences to Haskell: The
expression does not perform monadic desugaring, though there is a plan (ticket) to overload the syntax in the future.

3 Introduction of laziness

Although 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. The expression
f @ x
(read as: f suspend x) creates a thunk containing the function
and its argument
. When the value of this thunk is demanded at runtime, the function will be applied to its argument, yielding the result.

If 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.

The suspension operator
accepts a variable number of arguments. Uses of
map onto a set of primitive
functions, which can also be used if desired. To suspend the applications of
in the above example we can write:
 f a b  = f1 @ (f2 a) (f3 @ b)

which is equivalent to:

 f a b
  = do  x1 = f2 a
        x2 = suspend1 f3 b
        suspend2 f1 x1 x2