(x +
4)
will always evaluate to the same value, because
x
's value can't be changed. In contrast, in C,
C++, or Java, the value of (x + 4)
can change as
program execution proceeds if the value of x
is
changed.
rec_length [] = 0 rec_length (first:rest) = 1 + (rec_length rest)When the above function is called, Miranda will first check whether the argument matches
[]
(empty list) or
(first:rest)
(nonempty list) in form. If the
argument matches (first:rest)
, the first item in
the list is bound to first
and the rest of the list
to rest
for use in the function definition.
tree *
from lecture, in contrast with the more
limited (and not polymorphic) numtree
type, which
can only be used to store values of type num
in a
tree
in Miranda and
curly braces in C, C++, Java
- type inference - as in Miranda, where the compiler can determine
(in many cases) the type of an expression (including functions,
since they are first class) without the programmer having to
explicitly declare types (The compiler "infers" "types.")
- user-defined types - Types the language allows the user to
define; e.g., C++ and Java allow the user to define new classes
- polymorphic function - in Miranda and other functional
languages, a function with an argument whose type is not fixed
to a single, specific type; similar but not identical to
function overloading in C++ and Java, which is
sometimes called ad-hoc polymorphism, where only the
type signature and syntax of the function are reused, not the
implementation as well (as is the case with polymorphic
functions)
Thanks to our vocabulary scribes for today: Alison in AA and Brian in AB. Their words have been merged into the lists above.