Theorems for Free!

Parametrikistan
Joined January 2015
I wonder what this function does. flip :: Functor f => f (a -> b) -> a -> f b Wait, no I don't.
1
9
1
27
f :: Lens a b -> a -> b -> a This does one of two things. ∀ l x y. x /= y => f l x y x /= x Now I know which.
1
2
3
@rightfold is thinking of a function with the type (a -> b) -> a -> b The identity function specialized to functions.
2
length :: Foldable f => f a -> Int ∴ length (1, '2', "3") must return 1.
1
7
1
11
Parametricity retweeted
Generalize an abstraction because removing nonessential information clarifies its independent meaning. Re-use is accidental. @fronx
2
81
112
a -> (a, a, a, a) I definitely know what this function does. (a, a, a, a) -> a I almost know what this function does.
4
38
1
57
@catnaroek Fast & Loose Reasoning is Morally Correct.
1
2
f :: Monad f=>f T -> f T The result might depend on previous effect values g :: Applicative f=>f T -> f T This definitely doesn't though
2
4
8
Parametricity retweeted
Proof `fmap f.fmap g=fmap(f.g)` follows from `fmap id=id` and the free theorem: fpcomplete.com/user/edwardk/… /cc @BartoszMilewski @parametricity
5
14
24
Using Data.Foldable and parametricity, one can be sure that: foldMap f &&& foldMap g = foldMap (f &&& g)
3
3
f :: [a] -> [a] This type tells us some, but not all, things. ∀ x. f [x] = [x] ∀ x y. f (x++y) = f y++f x These tests tell us the rest.
4
26
26
f :: a -> a -> a This function does one of two things. test = f 1 2 == 1 Now it is disambiguated between those two.
8
6
Reminder. Fast & Loose Reasoning is Morally Correct.
1
9
6
A csharp<A>(A a) This function returns its argument.
3
(~.~<.~>\\+.) :: (Profunctor p, Functor f) => (a -> f b) -> p b r -> f (p a r) This operator clearly specifies what it does in the type.
5
56
63
Monad f => f a -> f b -> f b Any (a) values from the effect (f a) are not used.
1
Replying to @joel_burget
Correction. Applicative f => f a -> f a This function is implemented with only id, (<*) or (*>). Thanks @dino_joel
1
1
Applicative => f a -> f a This function is implemented with only id, (<*) or (*>).
1
1
IO Int -> a -> Int This function ignores both arguments.
1
5
3
String -> a -> a This function returns the second argument, ignoring the first.
1