DEV Community

Discussion on: Double negation in C#

Collapse
 
integerman profile image
Matt Eland

When I think of a tuple, I think more of "a small record" than "two things that are true together". I can definitely squint to see it, but I almost wonder if a new And type would be clearer to match the Either type.

Thread Thread
 
shimmer profile image
Brian Berns • Edited

I see. It turns out that a custom And type would be a small record as well - exactly the same shape as Tuple but with different names (i.e. the two types are "isomorphic").

Here's Tuple<T1, T2> from the .NET source code:

public class Tuple<T1, T2> : ... {

    private readonly T1 m_Item1;
    private readonly T2 m_Item2;

    public T1 Item1 { get { return m_Item1; } }
    public T2 Item2 { get { return m_Item2; } }

    public Tuple(T1 item1, T2 item2)
    {
        m_Item1 = item1;
        m_Item2 = item2;
    }

    ...

And here's a custom And type:

public class And<A, B> : ... {

    private readonly A _proof_of_A;
    private readonly B _proof_of_B;

    public A ProofOfA { get { return _proof_of_A; } }
    public B ProofOfB { get { return _proof_of_B; } }

    public And(A proof_of_A, B proof_of_B)
    {
        _proof_of_A = proof_of_A;
        _proof_of_B = proof_of_B;
    }

    ...

Usage:

var modus_ponens_input_tuple = new Tuple(A_implies_B, proof_of_A);
var modus_ponens_input_custom = new And(A_implies_B, proof_of_A);