Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Terminology Clarification: "Evaluating Objects" (as used in Prof. Giesl's Haskell lecture series)

I am confused with the terminology.

In this lecture at 38. min http://youtu.be/0u8eTSc5Gmo Prof. Giesl mentions the term "evaluation of objects". What does this mean more precisely?

I understand that you can evaluate an expressions in Haskell but what does it mean to evaluate an object?

Is an object itself an expression?

What is an object in Haskell ? Is the Int 1 an object ? Is a function an object?

What is an expression in Haskell ? Functions applied to objects?

Thanks for reading

Edit: according to SICP a number is an expression, so in this sense a data object (like numbers) is also an expression, so it can be evaluated.

Edit 2 : Below is the corresponding part from Prof. Giesl's lecture notes. In these lecture notes he says: "evaluation of an expression of type IO ()" so perhaps that is what he meant also in the video lecture when he said "evaluation of objects".

enter image description here

Edit 3: At 59.min Prof. Giesl writes and says 'Interpreter can only evaluate objects of type IO ()'.

At this point, I really start to have the feeling that when he says objects he means expression. Am I right ? So object is not a value (as suggested by some comments to this question) but an expression (in his lectures). Is this a correct interpretation ? Please someone more knowledgable in Haskell than me confirm my suspicion if it is correct.

enter image description here

Edit 4: The whole lecture series can be found here.

Edit 5: In the beginning of his 9th lecture he uses the term objects, what does he refer to ? I don't think he refers to values nor to expressions. Does he refer to data-objects in the sense of algebraic data types ?

I am totally confused by now. The basic question is, what does it mean when Prof. Giesl says "objects" ? What does he mean by that ? Especially in his 9th lecture lecture.

Edit 6:

From a private email communication with Prof. Giesl:

I used the words "object" and "value" as a synonym for "expression".
So when I speak about "evaluation of objects", 
in fact I mean "evaluation of expressions".

wrote Prof. Giesl.

like image 936
jhegedus Avatar asked Jun 04 '14 10:06

jhegedus


1 Answers

The term "object" in the Haskell language report

An object is often a synonymous for value in the language report:

§34.1.4 Marshalling lists of storable objects

withMany :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res

Replicates a withXXX combinator over a list of objects, yielding a list of marshalled objects

Here we are referring to [a] as a collection of objects of type a.

Therefore:

[4, 8, 42, 16, 23, 15]

is considered a collection of objects.

§3.15.1 Field Selection

Field labels are used as selector functions. When used as a variable, a field label serves as a function that extracts the field from an object.

With field labels we are referring to the record syntax and the functions automatically generated by it. Given, for example:

data Sample = Sample { a :: Int, b :: Double }

the following functions are generated:

a :: Sample -> Int
b :: Sample -> Double

Each function is extracting a specific value out of the "object".

§4.2.1 Algebraic Datatype Declarations

A data constructor of arity k creates an object with k components. These components are normally accessed positionally as arguments to the constructor in expressions or patterns. For large datatypes it is useful to assign field labels to the components of a data object.

In the above quote we can see that a data constructor creates an object. Therefore:

Just "ok"
Nothing

are both considered objects as well as:

[1, 3, 4]

§6.3.2 The Ord Class

The Ordering datatype allows a single comparison to determine the precise ordering of two objects.

Here we are referring to Ordering which is the data type used to express "less than", "greater than" and "equal to" in a comparison between two values.

The meaning in lecture 08

The professor says:

The evaluation of an object of type IO () has the effect that this action is performed.

He is referring to the fact that when an IO () value is effectively needed, the body of the action that calculates the IO () value is executed.

As an example, main requires an IO () data type:

main = putStr "sample"

When main will be called to run the program, "sample" will be applied to the function putStr (which has type String -> IO ()) in order to produce the IO () value, effectively printing sample as a side effect.

The "technical term" is defined as "a value":

§41.1 The IO monad

A value of type IO a is a computation which, when performed, does some I/O before returning a value of type a.

There is really only one way to ”perform” an I/O action: bind it to Main.main in your program. When your program is run, the I/O will be performed. It isn’t possible to perform I/O from an arbitrary function, unless that function is itself in the IO monad and called at some point, directly or indirectly, from Main.main.

The meaning in lecture 09

The professor says:

... return takes a value and gives you back the object where the value is incapsulated.

return's type is:

return :: a -> IO a

that is a function that takes any value and "generates" a value of type IO a containing that value. This is another case in which he is using object as a synonym of value.

Object vs expression

At this point, I really start to have the feeling that when he says objects he means expression. Am I right?

Well, no. I don't think you are right. An expression is not a value/object. As an example:

if x then 0 else 42

is an expression (as described at the beginning §3 in the language report) but not a value.

In Haskell an expression must yield a value but is not necessarily a value. On the other hand 0 and 42 are both values and expressions.

like image 88
Shoe Avatar answered Nov 06 '22 01:11

Shoe