Re: [Haskell-cafe] Is () a 0-length tuple?

Forgot to cc haskell-cafe. Trying again:
---------- Forwarded message ----------
From: Matthew Gruen
The syntax is similar, but what else is?
In JavaScript there is a "null" value, that is the only value of the null type.
Isn't () the same thing? The only value of the unary type?
Best,
titto
Pasqualino "Titto" Assini, Ph.D. http://quicquid.org/
In JavaScript's case, there is not a null type. The null value belongs to the 'object' type, whereas the undefined value belongs to the 'undefined' type. This is all a lot less useful when you realize that JavaScript has a dynamic type system. But this is JSON, not JavaScript. In JSON, arrays, objects, strings, and numbers can be any number of values. Booleans can be two values. Null can only be one value. Personally, I think a better mapping for () would be JSNull, since both have only one value in normal form. However, there is not necessarily any natural mapping between Haskell values and JSON values. The library tries to provide as many as possible, including (), which it happens to map to JSArray [] instead of JSNull. As long as the library is internally consistent, though, it should be fine.

2009/11/7 Matthew Gruen
Forgot to cc haskell-cafe. Trying again:
---------- Forwarded message ---------- From: Matthew Gruen
Date: Sat, Nov 7, 2009 at 2:16 PM Subject: Re: [Haskell-cafe] Is () a 0-length tuple? To: Pasqualino Titto Assini On Sat, Nov 7, 2009 at 2:00 PM, Pasqualino "Titto" Assini
wrote: The syntax is similar, but what else is?
In JavaScript there is a "null" value, that is the only value of the null type.
Isn't () the same thing? The only value of the unary type?
Best,
titto
Pasqualino "Titto" Assini, Ph.D. http://quicquid.org/
In JavaScript's case, there is not a null type. The null value belongs to the 'object' type, whereas the undefined value belongs to the 'undefined' type. This is all a lot less useful when you realize that JavaScript has a dynamic type system. But this is JSON, not JavaScript.
In JSON, arrays, objects, strings, and numbers can be any number of values. Booleans can be two values. Null can only be one value. Personally, I think a better mapping for () would be JSNull, since both have only one value in normal form. However, there is not necessarily any natural mapping between Haskell values and JSON values. The library tries to provide as many as possible, including (), which it happens to map to JSArray [] instead of JSNull. As long as the library is internally consistent, though, it should be fine.
What point are you trying to make by distinguishing JSON from JavaScript? JSON is a subset of JavaScript, they share the same type system. "Null can be only one value." This doesn't make sense to me, since as you say null is not a type, but a value. -- Deniz Dogan

On Sun, Nov 8, 2009 at 6:21 AM, Deniz Dogan
What point are you trying to make by distinguishing JSON from JavaScript? JSON is a subset of JavaScript, they share the same type system. "Null can be only one value." This doesn't make sense to me, since as you say null is not a type, but a value.
-- Deniz Dogan
It seems I underestimated the typedness of null in JavaScript :) I checked the ECMAScript specification, and it does refer to a "null type".. so titto was right.[1] My opinion is that JSON's 'type system' should be analyzed orthogonal to JavaScript's regardless. If JSON is a subset of JavaScript, it is primarily a syntactic one. When I said "Null can be only one value", implying that null is a type, I was referring to JSON's null, not JavaScript's null. In JSON, null *is* definitely a unit type. When considering mappings between Haskell and JSON in the case of (), we should see that () is a unit type in Haskell, null is a unit type in JSON (regardless of its role in JavaScript), and maybe try to associate them. —Matt [1] I was misled by the fact that typeof null = 'object'. The logic behind this, I think, is that null is meant to be bound to a variable that would otherwise be a reference to an actual object value. Many have criticized this result, e.g. Douglas Crockford ( http://javascript.crockford.com/remedial.html)

2009/11/8 Matthew Gruen
On Sun, Nov 8, 2009 at 6:21 AM, Deniz Dogan
wrote: What point are you trying to make by distinguishing JSON from JavaScript? JSON is a subset of JavaScript, they share the same type system. "Null can be only one value." This doesn't make sense to me, since as you say null is not a type, but a value.
-- Deniz Dogan
It seems I underestimated the typedness of null in JavaScript :) I checked the ECMAScript specification, and it does refer to a "null type".. so titto was right.[1] My opinion is that JSON's 'type system' should be analyzed orthogonal to JavaScript's regardless. If JSON is a subset of JavaScript, it is primarily a syntactic one. When I said "Null can be only one value", implying that null is a type, I was referring to JSON's null, not JavaScript's null. In JSON, null *is* definitely a unit type. When considering mappings between Haskell and JSON in the case of (), we should see that () is a unit type in Haskell, null is a unit type in JSON (regardless of its role in JavaScript), and maybe try to associate them.
—Matt
[1] I was misled by the fact that typeof null = 'object'. The logic behind this, I think, is that null is meant to be bound to a variable that would otherwise be a reference to an actual object value. Many have criticized this result, e.g. Douglas Crockford (http://javascript.crockford.com/remedial.html)
Let's keep in mind when reading the ECMAScript specification that JavaScript is merely based on it and breaks it on several different points. :) -- Deniz Dogan
participants (2)
-
Deniz Dogan
-
Matthew Gruen