Understanding Structural Equivalence

后端 未结 2 1405
名媛妹妹
名媛妹妹 2021-01-23 03:27

I have two types of structural equivalence ideas I am struggling to understand.

VAR_1 = int
VAR_2 = pointer to VAR_1

So here, I feel like they

2条回答
  •  被撕碎了的回忆
    2021-01-23 04:32

    This depends entirely on how the concepts of pointer and int are implemented, as well as what structural equivalence means in your particular scenario.

    Structural typing is concerned with whether one thing has the same structure as another thing, which means the implementation of the individual structures matters a great deal.

    Here is a quick pseudocode definition for both types.

    int definition
        32 bit value
    
    pointer definition
        32 bit value
    

    Two different types, but they contain the exact same members, even though semantically they are treated differently (the pointer is assumed to hold a memory address). These are structurally equivalent.

    Here's another implementation.

    int definition
        32 bit value
    
    pointer definition
        64 bit value
    

    Those aren't structurally equivalent, even though they both have a member called 'value'. How about this?

    int definition
        value
        other value
    
    pointer definition
        other value
        value
    

    These might not be considered the same because the members are in a different order, although they are named/typed the same.

    My point is that this is entirely up to the implementors of whatever language or environment this is a part of and what things mean in that world.

提交回复
热议问题