mdm
mdm

Reputation: 5594

What does the Haskell function forall do and where is it defined?

I'm reading A Little Lens Starter Tutorial and they use a seemingly magical function forall like this:

>>> forall $ \tuple -> view _1 tuple == fst tuple
True

What exactly does this function do and more importantly what package is it from. I can't find it using Hoogle, etc.

Upvotes: 6

Views: 222

Answers (2)

J. Abrahamson
J. Abrahamson

Reputation: 74364

Haha, embarrassed author here.

I invented forall to mime quickCheck and make intuitive sense, but not to be executable. In my defense, I took inspiration from the Little Schemer which happily introduces syntax and semantics far before they're executable in order to build intuition by practice.

Except, of course, my forall is not actually executable at all and it has lead to a lot of confusion.

So, my suggestion to anyone curious is to investigate quickcheck as a stand-in for forall. My suggestion to myself, now carried out, is to edit the tutorial to note my artistic license there.

Sorry about any trouble.

Upvotes: 5

bergey
bergey

Reputation: 3081

That's not actually executable code. See this answer: https://twitter.com/vh4x0r/status/429256064245067777

Upvotes: 4

Related Questions