3 ms·
Some functional languages make certain behaviors implicit, such as partial evaluation and laziness. However, these work better if they are explicit. They work b
by kazinator 10y ago
Some functional languages make certain behaviors implicit, such as partial evaluation and laziness. However, these work better if they are explicit. They work better because one of the two is severely confusing when implicit and the other potentially performs badly.
C:\Users\kaz>txr
This is the TXR Lisp interactive listener of TXR 162.
Use the :quit command or type Ctrl-D on empty line to exit.
1> (defstruct integers ()
val next
(:postinit (me)
(set me.next (lnew integers val (succ me.val))))
(:method print (me stream pretty-p)
(format stream "#<integers ~a ...>" me.val)))
#<struct-type integers>
2> (lnew integers val 0)
#<integers 0 ...>
3> *2.next
#<integers 1 ...>
4> *2.next.next
#<integers 2 ...>
5> *2.next.next.next
#<integers 3 ...>
Why would I want implicit laziness everywhere? The best of all worlds is to have expressions reduced to their values eagerly before a function call takes place.
When I don't want an expression evaluated in (what looks like) a function call, I can, firstly, make that a macro.
If I really want lazy semantics, I can have a decent vocabulary of lazy constructs that fit into the eager language. For instance for making objects lazily I have lnew, distinct from new.
Implicit laziness everywhere is academically stupid. You're drowning the execution of the code in an ocean of thunks and closures.
The pragmatic approach is best of making a compromise between making everything explicit and visible, yet keeping it syntactically tidy and convenient.
- lisper 10y ago> Why would I want implicit laziness everywhere? For the same reason you want automatic memory management: so you can fob off the job of figuring out where the thunks should go onto the compiler, just as you fob off the job of figuring out where the calls to malloc and free should go. At least that's the theory. It seems plausible to me. I think it's an open question whether my failure to grok Haskell is due to a problem with Haskell or the ossification of my brain.
- AnimalMuppet 10y agoNot trying to troll you here... To what degree do you use Lisp as an FP language? As a pure FP language? The forced purity may make Haskell a very different language. And, to return to your original complaint: If you dislike new languages, I bet XML drives you straight up the wall...
- lisper 10y ago> To what degree do you use Lisp as an FP language? As a pure FP language? It depends on what I'm doing, but I generally write in an OO style more than a functional style. Real problems have state. > If you dislike new languages I want to be clear that this is just a general observation. I don't dislike new things because they are new, I tend to dislike them because they are generally bad. But they are not all bad. Clojure is cool. WebASM is very cool. The work that has been done on Javascript compilers is nothing short of miraculous (even though the language itself still sucks). > I bet XML drives you straight up the wall Kind of, but not really. Yes, I dislike XML because it is nothing but S-expressions with a more complicated syntax. But it doesn't drive me up a wall because when I need to deal with XML I just parse it into S-exprs, do what I need to do, and render the results back into XML.
- bbcbasic 10y agoPure FP deals with state!
- kazinator 10y agoState is something that is best just embraced rather than "dealt with".
- bbcbasic 10y agoAn analogy to that is that OO doesn't embrace IO. Yet weirdly enough that makes OO-IO better than older languages that have built in commands to write to disk. Haskell doesn't have state but you have multiple models to choose from, from simple folds to STM or State or Reader or Writer Monads all of which serve different purposes and do different jobs well.
- kazinator 10y agoOOP absolutely embraces I/O. I/O begs to be OOP and makes, hands down, the best use case for illustrating OOP.
- kazinator 10y agoIt's not the same. Here is why: the program correctness doesn't depend on when (or even whether!) that automatic memory management happens. Lisp systems have been bootstrapped without having a working garbage collector upfront. Short-lived Lisp images run as processes in a conventional OS might never have a chance to collect garbage. Laziness has precise semantics which has to unfold properly, or else things don't work. Delaying evaluation is not the same thing as delaying reclamation. They are opposite in a sense, because we only allow something to be reclaimed when it is "of no value".
- bbcbasic 10y agoFailure to grok Haskell is probably due to the lack of easy accessible literature on it. Plus with so few other people groking it there isn't as much osmosis available.
- cronjobber 10y ago> Why would I want implicit laziness everywhere? Modularity; see the stone age paper discussed yesterday: https://news.ycombinator.com/item?id=13129540 https://news.ycombinator.com/item?id=13129540 > Functional programming languages provide two new kinds of glue - higher-order functions and lazy evaluation. Using these glues one can modularise programs in new and exciting ways, and we’ve shown many examples of this. > This paper provides further evidence that lazy evaluation is too important to be relegated to second-class citizenship. It is perhaps the most powerful glue functional programmers possess.
- kazinator 10y agoThe paper claims in its conclusion that it has provided evidence (what is more, "further evidence") yet I can't find any in there. It argues that you can achieve a certain useful separation between programs together when one produces data for the other. This can be achieved in a very satisfactory way with explicit streams (i.e. lazy lists). It can be satisfied with delimited closures, coroutines, threads and often with lexical closures. Not to mention Icon-style generators. Lazy lists can be incorporated into the language so that their cell are first-class objects and substitute for regular eager cells smoothly. (Thank you, OOP). The paper is actually wrong there, because laziness alone will not provide the kind of separation that g can begin executing, such that f then only executes when an item is required. Not for an arbitrary f! Suppose f traverses a graph structure recursively and yields some interesting items. Lazy eval alone isn't going to allow the f traversal to behave as a coroutine controlled by g, proceeding only as far as g continues to be interested in further items. The author is attributing to lazy evaluation magical powers that it doesn't have.
- deleted 10y ago[deleted]