3 ms·
Laziness is a run time question. Nullability is a compile time question. Nullness, given nullability, is a run time question. Laziness in no way enters into
by dllthomas 12y ago
Laziness is a run time question. Nullability is a compile time question. Nullness, given nullability, is a run time question. Laziness in no way enters into this.
- taeric 12y agoSee my response upthread https://news.ycombinator.com/item?id=8007555 https://news.ycombinator.com/item?id=8007555. Basically, I was under the impression that it wouldn't actually unwrap the Maybe until you went to actually use it. I think I was just holding the laziness a little too magically. :)
- dllthomas 12y agoThat is essentially true, actually - it will be a thunk until you force it. That is the case whether or not Maybe is involved, though.
- taeric 12y agoI'm confused, then. Sounds like it can have obscure, "doesn't bite you immediately and appears far away from where the problem actually is," properties that were attributed to null. That is, at the point that a Maybe String statically changes to a String is not necessarily where the program will explode. A lot like a null assign. (Again, in a lazy language. Unless I'm mistaken on this subthread, the point was simply that you can still have that level of WTFery with Maybe that you can have with a null.)
- dllthomas 12y agoMaybe doesn't have to be involved at all. The point where the exception is raised is the point when the relevant thunk is forced. It is certainly the case that this can be problematic. This is an artifact of the intersection of laziness and IO, and there are methodological approaches (helped very much by libraries) to it, but it is a similar problem to nulls. Note that there are plenty of languages that are strict and provide an optional type - including Idris, I think, which is Haskell-like, dependently typed, and strictly evaluated.
- taeric 12y agoRight, this particular subthread was started by my saying that the laziness of Haskel could trip you up on the conversion from a Maybe x to an x. Which seems to be true, from what we are saying now. Now, rereading the beginning, the reference was to a "Haskel like" type. So, I think I was definitely off the rails on this. I do feel I learned something going down this particular rabbit hole, though. Thanks!
- dllthomas 12y agoAs I just wrote elsewhere, the typical ways you get from Maybe x to x in Haskell don't have room to get tripped. There is a function, fromMaybe, which takes a Maybe x and gives you an x... but it also takes a default! Often even more useful is the maybe function: maybe :: output -> (input -> output) -> Maybe input -> output This takes a default output to use if you're given Nothing, a function to apply to the input and generate an output if you're given Just an input, and Maybe the input, and gives you the resulting output. As I said this is often more useful than "and use this default", because quite often the value you want to generate when it's Nothing is outside the image of the input under the function in question. For instance: maybe "no number" show maybe_integer There's no number I can pass to show to get "no number", maybe lets me very conveniently avoid trying to force one.