tag:blogger.com,1999:blog-178174920347765771.post7037726222994626038..comments2023-10-30T09:20:21.742-07:00Comments on One Div Zero: Void vs UnitJames Iryhttp://www.blogger.com/profile/02835376424060382389noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-178174920347765771.post-13680046001350164062012-10-26T10:24:23.884-07:002012-10-26T10:24:23.884-07:00As far as java.lang.Void goes it is similar to &qu...As far as java.lang.Void goes it is similar to "unit" in that it has only one member - "null", so it is suitable for that usage in Java. It's also similar to the bottom type in that null is a member of all non-primitive types. However, the similartiy stops there. If it were truly the "top" type it would be the superclass of Object. If it were truly the bottomDobes Vandermeernoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-32497220258163327822011-05-24T07:30:47.412-07:002011-05-24T07:30:47.412-07:00>>> type(None) == None
False
>>>...>>> type(None) == None<br />False<br /><br />>>> type(None)<br /><type 'NoneType'>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-20150034270331523742011-05-24T04:54:59.691-07:002011-05-24T04:54:59.691-07:00The only reason you can't write 'x = print...The only reason you can't write 'x = print "hello"' in python is that print is a special statement defined by the language rather than a function, which is completely irrelevant here (and which is no longer true in 3.x). You can define a function 'def p(s): print s' and then write 'x = p("hello")' and it works just fine. You'll get None, the Falcotron23noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-26484920189351871702009-07-31T13:26:49.856-07:002009-07-31T13:26:49.856-07:00Hey, James, could you provide us a feed with the c...Hey, James, could you provide us a feed with the complete contents of your posts (instead of just the first few words). I love your blog, but it's such a pain to switch between the reader and the browser. Pleeease! :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-69445476362891997622009-07-29T16:57:19.840-07:002009-07-29T16:57:19.840-07:00@Jiri Palecek,
For more than you ever wanted to ...@Jiri Palecek, <br /><br />For more than you ever wanted to know about the death of concepts in C++0x, see http://lambda-the-ultimate.org/node/3518James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-59226011980689742542009-07-29T14:58:16.505-07:002009-07-29T14:58:16.505-07:00In the 4th footnote, you say C++0x won't have ...In the 4th footnote, you say C++0x won't have concepts. Do you have any references backing that? Because in the last working draft, concepts are present, and according to the documents on open-std.org it has been named as a feature in the registration document. If you meant other "concepts" than the constrained templates, consider this comment void :-)<br /><br />I've got other Unknownhttps://www.blogger.com/profile/01600013395920370438noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-62715092748443240792009-07-27T19:31:11.313-07:002009-07-27T19:31:11.313-07:00One more thing.
If you declare a method like so: ...One more thing.<br /><br />If you declare a method like so: void doFoo(), the implementation doesn't need to return anything.<br /><br />But if the method sig is: Void doFoo();, you must return null.Gavin Bonghttps://www.blogger.com/profile/03576181730840628506noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-24081917144684110662009-07-27T19:07:24.294-07:002009-07-27T19:07:24.294-07:00In the google android sample code, java.lang.Void ...In the google android sample code, java.lang.Void is used everywhere.<br /><br />e.g. <br />AsyncTask<Void,Void,Void>Gavin Bonghttps://www.blogger.com/profile/03576181730840628506noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-9482978187141702362009-07-24T22:16:21.487-07:002009-07-24T22:16:21.487-07:00@James, re: “There's a terminological confusio...@James, re: “There's a terminological confusion here.”<br /><br />There is no confusion. I was simply fishing for a reaction. =)liyang.huhttps://www.blogger.com/profile/14642050586254856288noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-77091362581802073312009-07-24T15:00:37.223-07:002009-07-24T15:00:37.223-07:00> if you transliterate a simple Java IO program...> <i>if you transliterate a simple Java IO program into OCaml you'll replace voids with Units and the program will work the same way. You would not replace them with Scala's bottom type</i><br /><br />When I transliterate into O'Caml I never use any of Scala's typs ;)heliumhttps://www.blogger.com/profile/14171590551274027449noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-1412302447579877622009-07-24T08:54:44.724-07:002009-07-24T08:54:44.724-07:00@liyang,
There's a terminological confusion h...@liyang,<br /><br />There's a terminological confusion here. Some type theorists sometimes use the word "void" to mean the bottom type. At the type level the bottom type is falsity as you point out where the unit value is more truthy. However, C style voids do not correspond with the bottom type. If they did, then you could write things like<br /><br />String x = print("James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-72174323222599288322009-07-24T07:45:47.609-07:002009-07-24T07:45:47.609-07:00Would you please expand on your fifth note, saying...Would you please expand on your fifth note, saying that a Python tuple is really just a list? "A tuple is an ordered fixed size collection of values of (possibly) different types" seems to match Python's tuple semantics pretty much exactly. What am I missing?Marius Gedminashttps://www.blogger.com/profile/15155998626202067226noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-79445411969670971002009-07-24T07:44:02.701-07:002009-07-24T07:44:02.701-07:00Excellent.
"reulst" ? :-)
Cheers
Steph...Excellent.<br /><br />"reulst" ? :-)<br /><br />Cheers<br />StephanStephan.Schmidthttps://www.blogger.com/profile/03845125686370893937noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-1609905392244413372009-07-24T07:04:42.192-07:002009-07-24T07:04:42.192-07:00I'm not expert, but I'm almost positive th...I'm not expert, but I'm almost positive that Curry-Howard doesn't deal with Void vs Unit. James is right on this issue.<br /><br />I've always thought of void as being a unit type with no members. Even back when I was learning Java, it seemed more than a little odd.Daniel Spiewakhttps://www.blogger.com/profile/17323566514229790079noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-67328153598693770702009-07-24T06:15:42.368-07:002009-07-24T06:15:42.368-07:00“Void and unit are essentially the same concept.” ...“Void and unit are essentially the same concept.” — only insomuch as the Booleans False and True (respectively) are essentially the same concept, unless you wish to contradict Curry-Howard.<br /><br />Here's a tuppence. Go buy yourself a real type system.liyang.huhttps://www.blogger.com/profile/14642050586254856288noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-14773930962939979692009-07-24T05:24:41.609-07:002009-07-24T05:24:41.609-07:00@Jeremy,
None is used to mean something like null...@Jeremy,<br /><br />None is used to mean something like null in the C derived languages. But as the footnote mentions, in dynamically typed languages such values can be punned and used in place of (). Still, Python doesn't really count. You can't write 'x = print "hello"' in Python. In an impure functional language you can and x would be ().<br /><br />@AlBlue,<br />James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-56361229696136600812009-07-24T00:36:59.012-07:002009-07-24T00:36:59.012-07:00The type 'Void' is purely used by reflecti...The type 'Void' is purely used by reflection to denote a return type of void. In fact, Void is a meta-type (it's the type of types) but in both cases, there is no value X such that X:void, or that you could pass in as an argument to a function. In other words, if f() is of type 'void', there is no way of constructing a function g(f()).AlBluehttps://www.blogger.com/profile/06362201865553416948noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-33774087617556011342009-07-23T22:48:10.933-07:002009-07-23T22:48:10.933-07:00Where does Python fit in, having first-class funct...Where does Python fit in, having first-class functions and the None type?Jeremy R. Fishmanhttps://www.blogger.com/profile/10422181943870295667noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-13706258273045810902009-07-23T16:59:57.959-07:002009-07-23T16:59:57.959-07:00@JH - in any Turing complete language unit has two...@JH - in any Turing complete language unit has two values, () and bottom it's just that strict languages will diverge on bottom in cases where Haskell does not. However, explaining bottom as a value to reforming C/C++/C#/Java programmers is just a bit much when the thought of void as having a value is already pretty "out there."<br /><br />My next article is about the bottom type.James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-62905954440211153372009-07-23T16:45:11.925-07:002009-07-23T16:45:11.925-07:00But unit, as its name somewhat implies, has exactl...<i>But unit, as its name somewhat implies, has exactly one value</i><br /><br />I think that in Haskell, at least, the type unit may have two values: () or bottom.JHnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-78902251674028471522009-07-23T15:50:58.164-07:002009-07-23T15:50:58.164-07:00Eek, I did forget Void. Hmmm, have to think about...Eek, I did forget Void. Hmmm, have to think about how to edit it in.James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-85586042242982641062009-07-23T15:33:11.470-07:002009-07-23T15:33:11.470-07:00Quick note: I think you're forgetting about ja...Quick note: I think you're forgetting about java.lang.Void. This is the "official" type of the non-existent value for "void". Of course, since it's a type with no members, it's really almost as bad as not existing in the first place. The one thing it's good for is situations like what you demonstrated (converting a void function into a value).<br /><br />As Daniel Spiewakhttps://www.blogger.com/profile/17323566514229790079noreply@blogger.com