concept Prop in category functional programming

appears as: Prop, Prop
Functional Programming with Kotlin

This is an excerpt from Manning's book Functional Programming with Kotlin.

Here, we’ve simply invented a new type, Prop (short for property) for the result of binding a Gen to a predicate. We might not know the internal representation of Prop or what other functions it supports, but based on our prior discussion in section 8.1, it should be combined with other Prop instances through the use of an and method. Let’s introduce that as a new interface:

interface Prop {
    fun and(p: Prop): Prop
}

Assuming the following representation, use check to implement and as a method of Prop.

interface Prop {
    fun check(): Boolean
    fun and(p: Prop): Prop = TODO()
}

In this representation, Prop is nothing more than a non-strict Boolean. Any of the usual Boolean functions (AND, OR, NOT, XOR, and so on) can easily be defined for Prop. But a Boolean alone is probably insufficient. If a property fails, we might want to know how many tests succeeded first. We might also be interested in what arguments produced the failure. And if a property succeeds, it would be useful to know how many tests it ran. Next, let’s encode this information by returning an Either to indicate success or failure:

typealias SuccessCount = Int

interface Prop {
    fun check(): Either<String, SuccessCount>
    fun and(p: Prop): Prop
}

For now, we’ve assigned the failure case to be String, but what type should we return on the left side? We don’t know anything about the type of the test cases being generated. Should we add a type parameter to Prop and make it Prop<A> so check could return Either<A, SuccessCount>. Before going too far down this route, let’s ask ourselves whether we really care about the type of the value that caused the property to fail. We don’t really. We would only care about the type if we were going to do further computation with the failure.