628 karma · joined December 22, 2012
You can often use the "for" function for things analogous to effectful imperative loops. http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-T...
The idea is that the only explicit recursion is contained in generic combinators "fold_result" and "unfold_result" that are "boring" in the sense that they can be derived mechanically from the "resultF" data type and do not actually know about the binary search; they just do recursion.
In practice, folds and unfolds tend to be more useful for other things.
Imagine you need a 2-parameter "Lasagna" datatype wich is a non-empty list of alternating "a" and "b" elements. It could be used to model something like a timeline, perhaps.
Instead of constructing it by hand, you could express it as a composition of other stuff:
import Data.List.NonEmpty
import Data.Bifunctor
import Data.Bifunctor.Tannen
type Lasagna = Tannen NonEmpty (,)
example :: Lasagna Char Int
example = Tannen $ ('a',3) :| [('b',4),('d',6)]
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-L...https://hackage.haskell.org/package/bifunctors-5.4.2/docs/Da...
That type has a whole bunch of useful instances without even having to auto-derive them.
And you could have functions that manipulated the pairs without caring what shape the "outer functor" has.
"streaming" provides a Stream type which is parameterized by a Functor. The main module in the package provides very general functions which work for any functor and often involve natural transformations and functor compositions and sums. http://hackage.haskell.org/package/streaming-0.1.4.5/docs/St...
The "Streaming.Prelude" instantiates the functor with a pair type and provides the more concrete API that one would expect from a streaming library. http://hackage.haskell.org/package/streaming-0.1.4.5/docs/St...
It also comes with a contract, like the contracts of "equals", "hashCode" or Comparable in Java. The contract says that the operation must be associative, and that the element you produce out of thin air must be neutral: when you combine it with another element it leaves the other element unchanged.
One benefit of having such general interfaces is that you can reuse code across a wide range of domains. For example: the Comparator interface in Java can be seen as a monoid, with the "thenComparing" function as the combination operation: https://docs.oracle.com/javase/8/docs/api/java/util/Comparat... You could build a list of comparators and concatenate it, map a function that produces a comparator over a list and concatenate it, and so on.
Another benefit is that you can be quite general when specifying requirements for your functions. In Haskell, the Writer monad only requires the type of the accumulator to be an instance of Monoid. So you can user regular lists, difference lists, or the integers under addition.
Also in Haskell some composite types automatically satisfy an interface if their components do, saving you work. For example, a tuple of monoids is automatically a monoid. Any function that returns a monoid is itself a monoid as well. (Functions that begin and end in the same type can be monoids in a different way: the neutral element is the identity function and the combination operation is composition.)
What are the benefits of this approach vs. explicitly waiting for the things that should appear in the page?
You can also define your own; they are basically functions from a WebDriver object to some other thing (usually a Boolean).
http://seleniumhq.github.io/selenium/docs/api/java/org/openq...
"Hothouse" is quite a fun read as well.
> And while recorders present some challenges, manually coding UI-level tests make the maintainability issue an order of magnitude worse.
In my experience, writing the tests manually for sufficiently "regular" applications ends up being more maitainable because you can put repeated logic in shared functions and classes, making it easier to adapt to changes in the GUI. Page Objects are an example of that: https://github.com/SeleniumHQ/selenium/wiki/PageObjects
Also, writing the tests manually lets you use "explicit waits". http://elementalselenium.com/tips/47-waiting Specifying exactly what we expect to happen tends to be more robust (and faster) than either using static sleeps or some kind of implicit wait. Recorders tend to have problems finding concrete things to wait for, especially for very dynamic pages.
(That said, I'm not against using something like Chrome DevTools to identify elements in the page, evaluate potential selectors, and so on. That is indeed useful.)
GUI tests suites, especially those created with recorders, are prone to become unmaintainable beasts full of flaky tests.
This old interview with Bret Pettichord makes good points about the use of recorders: https://youtu.be/s_CUPs6xAWw?t=590
But perhaps it wouldn't save much code compared to custom-made parsers.
> A pair of wings, a different respiratory system, which enabled us to travel through space, would in no way help us, for if we visited Mars or Venus while keeping the same senses, they would clothe everything we could see in the same aspect as the things of the Earth. The only true voyage, the only bath in the Fountain of Youth, would be not to visit strange lands but to possess other eyes, to see the universe through the eyes of another, of a hundred others, to see the hundred universes that each of them sees, that each of them is; and this we do, with great artists; with artists like these we do really fly from star to star.
R. A. Lafferty has a delightful short story with this very premise, appropriately titled "Through other eyes": https://archive.org/stream/Future_Science_Fiction_47_1960-02...
I suppose Kafka would work in programming, had he been born in our time.
It is strange, but for a good chunk of time religious thinkers were "more right" about subjects like the eternity of the universe than the prevailing aristotelian philosophers, sometimes deploying surprisingly modern-sounding ideas in the process. I'm thinking of authors like Philoponus https://historyofphilosophy.net/philoponus and Crescas https://historyofphilosophy.net/crescas
The Stanford Encyclopedia of Philosophy has an entry on the condemnation of 1277: https://plato.stanford.edu/entries/condemnation/
Another cool feature of Idris is elaborator reflection https://www.youtube.com/watch?v=pqFgYCdiYz4 which I believe has no direct Haskell analogue (template Haskell perhaps?)
The code in this other post about implementing string distance metrics is also quite imperative: https://markkarpov.com/post/migrating-text-metrics.html
What were the main "practical" approaches for natural language understanding back then?
> "Is the truth depressing? Some may find it so. But I find it liberating, and consoling. When I believed that my existence was a further fact, I seemed imprisoned in myself. My life seemed like a glass tunnel, through which I was moving faster every year, and at the end of which there was darkness. When I changed my view, the walls of my glass tunnel disappeared. I now live in the open air. There is still a difference between my life and the lives of other people. But the difference is less. I am less concerned about the rest of my own life, and more concerned about the lives of others."
But I wonder if such view can have more sinister interpretations. For example, a "parfitian" might become obsessed in imposing his own worldview and tastes on other people, feeling that this affords him a measure of "immortality". A bit like the ancient greek heroes' thirst for fame, perhaps. https://en.wikipedia.org/wiki/Kleos#cite_ref-4
> "When doubts invade us and cloud our faith in the immortality of the soul, a vigorous and painful impulse is given to the anxiety to perpetuate our name and fame, to grasp at least a shadow of immortality. And hence this tremendous struggle to singularize ourselves, to survive in some way in the memory of others and of posterity … Each one seeks to affirm himself, if only in appearance … Man habitually sacrifices his life to his purse, but he sacrifices his purse to his vanity. He boasts even of his weaknesses and his misfortunes, for want of anything better to boast of, and is like a child who, in order to attract attention, struts about with a bandaged finger." —Miguel de Unamuno, The Tragic Sense of Life
Another interesting paper by Meir Kohn, this one about the evolution of the bill of exchange: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=151849
Cont r a is a computation that knows how to produce an "a" but, instead of returning it directly, passes it to a function that takes the "a" and produces an "r".
Compared to typical sequential execution, this gives more power to the "current" phase of the computation, because it might choose to invoke the passed a -> r function more than one time, none at all, inspect the resulting "r" and change course based on the result, etc.