Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand the sentence "or that it evaluates to bottom"?

I see these sentences on the book "functional programming in scala":

If the evaluation of an expression runs forever or throws an error instead of returning a definite value, we say that the expression does not terminate, or that it evaluates to bottom. A function f is strict if the expression f(x) evaluates to bottom for all x that evaluate to bottom.

Sorry for my poor English, I found myself can't understand this sentence well:

or that it evaluates to bottom

Two parts I can't understand:

  1. Is "it evaluates to bottom" the same to "the expression does not terminate", or opposite?
  2. What does "bottom" mean here?

Thanks

like image 664
Freewind Avatar asked Sep 16 '14 14:09

Freewind


1 Answers

"Evaluates to bottom" is a way to say that an expression doesn't return normally: it throws an exception, gets stuck in a loop, or halts the program. The reason that phrase is used is because sometimes it's convenient to pretend that all expressions evaluate to a value. Once you pretend that non-returning expressions produce a value called bottom you can simplify your description of how expressions interact.

The bottom type (in Scala called Nothing) is related: it's the type of expressions that can only produce the bottom value (i.e. not terminate normally). In Scala the expression "throw new RuntimeException()" has the bottom type (Nothing), and in this terminology we would say it produces the bottom value.

These uses of the word "bottom" come originally from formal logic and then into programming via formal language semantics.

like image 99
James Iry Avatar answered Oct 13 '22 20:10

James Iry