10 ms·
(serve (fry (add-pan kale (fry (add-pan (dice onions)))))
by samatman 13y ago
(serve (fry (add-pan kale (fry (add-pan (dice onions)))))
- taeric 13y agoYou joke, but I've often thought how would one write a traditional recipe in a programming language in such a way that it would make sense. Same for "do it yourself" furniture. Ultimately, I always fall back on programs not having a good concept of "consuming" or otherwise changing a variable. This is clearly doable, and elsewise it was referenced as linear typing (new to me).
- angersock 13y agoC++ with references or C with pointers or Fortran with inout variables would accomplish this, just using normal procedural code: contents = open(&ramen); add_into( &pot, waterfactory() ); add_into( &pot, contents ); add_heat( &pot ); sleep( RAMENCOOKTIME ); tasty_ramen = open(&pot);
- taeric 13y agoRight. I did not think I was stating anything grand here. I was simply pointing out that "imperative" mixed with "mutable" state is not something that is hard for users to grasp. Especially when limited in scope to single threads of action. The hard part comes in making sure this "type checks." That is, if you had it dependently typed such that you could not "add_into( &pot, contents );" until after you had "add_into( &pot, waterfactory() );" than you could conceivably catch more bugs. The trick, to me, is that the "type" of "pot" is not fixed in this. Since I consider the "type" to be dependent on its state. I know this can be done with generic and higher order programming, but usually not with the same reference. That is, each call would create a new reference to pot such that the next one fed off of that. Thing is, that doesn't read well. (I mean, it does for toy examples, but doesn't for long ones.) Make sense?
- angersock 13y agoSure.
- taeric 13y agoI feel compelled to give kudos for by far the most readable of the "as program" directions here. Don't get me wrong, I can read most of the other examples, but this is the only one that really reads more true to how you would describe the process to someone and really underscores where I think a lot of the functional advocacy falls flat.
- cynicalkane 13y agoBetter is (->> onions dice add-pan fry (add-pan kale) fry serve))
- agscala 13y agoAmazing. What's the ->> operator called?
- breckinloggins 13y agoA monad ;-) No, but seriously, you can think of (->> foo bar baz quux) As a way of saying: Within the context of computing one thing and passing that result to the next thing with a common carrier object of "foo", do bar, then baz, then quux within that context, each operating on foo. In VB you could do: with someFile readIt() processIt() writeIt() See the similarity? By the way, monads are a way to abstract this even further so that not only can you model the context of "do something to a thing then do the next thing then do the next", but almost every other kind of context you could think of. EDIT: as has been pointed out, this isn't really a monad, but it's an example of something monad-like that helps me grasp the larger concept better. Also, fixed the syntax.
- tel 13y agotype Recipe = Food -> Food serve . fry . addPan kale . addPan (dice onions) :: Recipe