Tool for generating free theorems for sublanguages of Haskell.
Questions tagged [free-theorem]
8 questions
14
votes
1 answer
For different possible Monad instances of a type, is the implied Functor instance always the same?
According to the Typeclassopedia and this link a type can only have a single Functor instance (there's a proof in the link). But it is my understanding that it is possible for a given type to have multiple possible Monad instances, is this right?…

Rafael S. Calsaverini
- 13,582
- 19
- 75
- 132
13
votes
1 answer
In Idris, can I prove free theorems, e.g. the only (total) function of type `forall t. t -> t` is `id`?
For sufficiently polymorphic types, parametricity can uniquely determine the function itself (see Wadler's Theorems for free! for details). For example, the only total function with type forall t. t -> t is the identity function id.
Is it possible…

Philip Dorrell
- 1,658
- 11
- 15
7
votes
2 answers
Is the functor distribution law for the `Alt` typeclass trivial?
I was looking at the laws for the Alt typeclass, which looks like this:
class Functor f => Alt f
where
() :: f a -> f a -> f a
One of the laws goes like this:
<$> left-distributes over : f <$> (a b) = (f <$> a) (f <$> b)
More…

Asad Saeeduddin
- 46,193
- 6
- 90
- 139
7
votes
2 answers
Law for type [[a]] -> ([a], [a])
I am trying to do this question from my homework:
Given arbitrary foo :: [[a]] -> ([a], [a]), write down one law that the function foo satisfies, involving map on lists and pairs.
Some context: I am a first year undergrad taking a course of…

Jingjie Yang
- 605
- 2
- 10
- 22
3
votes
1 answer
Parametricity-exploiting proofs in Agda
Reading this answer prompted me to try to construct, and then prove, the canonical form of polymorphic container functions. The construction was straightforward, but the proof stumps me. Below is a simplified-minimized version of how I tried to…

Cactus
- 27,075
- 9
- 69
- 149
2
votes
1 answer
Free theorem for fmap
Consider the following wrapper:
newtype F a = Wrap { unwrap :: Int }
I want to disprove (as an exercise to wrap my head around this interesting post) that there’s a legitimate Functor F instance which allows us to apply functions of Int -> Int type…

Zhiltsoff Igor
- 1,812
- 8
- 24
2
votes
1 answer
Finding a "free theorem"
How do I derive the free theorem for the type:
data F a = C1 Nat | C2 Bool Nat a
where Nat is simply data Nat = Z | S Nat?
In principle, this can be answered by the Haskell 'free-theorems' package, but it's too elderly to compile under any GHC…

NietzscheanAI
- 966
- 6
- 16
1
vote
1 answer
Paramcoq: Free theorems in Coq
How can I prove the following free theorem with the plugin Paramcoq?
Lemma id_free (f : forall A : Type, A -> A) (X : Type) (x : X), f X x = x.
If it is not possible, then what is the purpose of this plugin?

Bob
- 1,713
- 10
- 23