# Type checking, query for parent or subtypes

**URL:** <https://forums.fsharp.org/t/type-checking-query-for-parent-or-subtypes/1854>\
**Category:** General\
**Created:** [September 17, 2021, 9:18am UTC](https://forums.fsharp.org/t/type-checking-query-for-parent-or-subtypes/1854 "2021-09-17T09:18:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zoidboom](https://avatars.discourse-cdn.com/v4/letter/z/77aa72/32.png) [@Zoidboom](https://forums.fsharp.org/u/Zoidboom)\
**Post date:** [September 17, 2021, 9:18am UTC](https://forums.fsharp.org/t/type-checking-query-for-parent-or-subtypes/1854/1 "2021-09-17T09:18:26Z")

</div>

Hi, how do I check in the below if a Square is also a Rectangle, I know they are dicriminated but can I query the hierarchical relationship?

```auto
type Shape =
    | Flat
        | Rectangle
            | Square
        | Circle

```

Another question, how is the :? operator applied. Can it be used in these matters.

---

<div class="post-metadata">

**Author:** ![Prash](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/prash/32/815_2.png) [@Prash](https://forums.fsharp.org/u/Prash)\
**Post date:** [September 17, 2021, 12:44pm UTC](https://forums.fsharp.org/t/type-checking-query-for-parent-or-subtypes/1854/2 "2021-09-17T12:44:20Z")

</div>

That type definition doesn’t describe the hierarchy you’re talking about. Perhaps you know that already and it was meant as illustrative pseudo-code. But if that’s the case, it’s not clear to me what you’re asking here. Can you provide a minimal working code sample that sets up the problem?

---

<div class="post-metadata">

**Author:** ![Zoidboom](https://avatars.discourse-cdn.com/v4/letter/z/77aa72/32.png) [@Zoidboom](https://forums.fsharp.org/u/Zoidboom)\
**Post date:** [September 17, 2021, 1:00pm UTC](https://forums.fsharp.org/t/type-checking-query-for-parent-or-subtypes/1854/3 "2021-09-17T13:00:44Z")

</div>

Hi Prash,

Thanks for taking time. If I instantiate a Square case, is there a way to test if that Square is conceptually child of case Rectangle. Does that clarify? How do I test for this IS-A relationship. Is it possible with DU’s

Best Regards Jesper.

---

<div class="post-metadata">

**Author:** ![Prash](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/prash/32/815_2.png) [@Prash](https://forums.fsharp.org/u/Prash)\
**Post date:** [September 17, 2021, 1:53pm UTC](https://forums.fsharp.org/t/type-checking-query-for-parent-or-subtypes/1854/4 "2021-09-17T13:53:47Z")

</div>

A single DU type definition can contain multiple cases which are all siblings at the same level. It only creates one type. Your example shows them indented at different levels but that indentation is misleading and they should all be in line. If you want to use a DUs to create a hierarchy like this you need multiple DUs, which means multiple types:

```auto
type Rectangle =
    | Square

type Flat =
    | Rectangle of Rectangle
    | Circle

type Shape =
    | Flat of Flat

```

Now when we have a `Rectangle` it means we have a `Rectangle` type. In normal statically typed programming, the compiler and the programmer would know the type of any given value, so there is no need to do a type test at runtime.

I hope that helps to clarify. It’s useful to understand that there’s a difference between a DU type and a DU case: The DU itself is the type, and the case is a value that has that type.
