# Issue with type inference in Verse generics

**URL:** <https://forums.unrealengine.com/t/issue-with-type-inference-in-verse-generics/1979759>\
**Category:** Issues and Bug Reporting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [August 17, 2024, 4:49am UTC](https://forums.unrealengine.com/t/issue-with-type-inference-in-verse-generics/1979759 "2024-08-17T04:49:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smckdwn16](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smckdwn16](https://forums.unrealengine.com/u/smckdwn16)\
**Post date:** [August 17, 2024, 4:49am UTC](https://forums.unrealengine.com/t/issue-with-type-inference-in-verse-generics/1979759/1 "2024-08-17T04:49:00Z")

</div>

### Please select what you are reporting on:

Unreal Editor for Fortnite

### What Type of Bug are you experiencing?

Verse

### Summary

HI all,

I’m trying to write a generic function that finds the indices of duplicate entries in an array. The problem I’m having is with the line `Key > MaxElement`. The compiler can’t infer that the type of MaxElement and Key are the same:

```auto
    Find_Equal_Elements<public>(Array: []t where t:subtype(comparable))<transacts>:[]int=
        if (Array.Length <= 1):
            return array{0}

        var Duplicates: [t][]int = map{}
        
        for (Index->Element : Array):
            if (set Duplicates[Element] += array{Index}) {}
        
        var Indices: []int = array{0}

        if (var MaxElement: t = Array[0]):
            for (Key->Value : Duplicates):
                if (Key > MaxElement):
                    set MaxElement = Key
        
            
            if (ElementIndices := Duplicates[MaxElement]):
                set Indices = ElementIndices
            
        Indices

```

### Steps to Reproduce

Enter the above code in VS Code and you’ll see the compiler error about no overload operator for \>

### Expected Result

I expect the compiler to infer that both types are the same

### Observed Result

Error

### Platform(s)

Windows 10

---

<div class="post-metadata">

**Author:** ![Noldstein](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Noldstein](https://forums.unrealengine.com/u/Noldstein)\
**Post date:** [August 19, 2024, 4:40pm UTC](https://forums.unrealengine.com/t/issue-with-type-inference-in-verse-generics/1979759/2 "2024-08-19T16:40:34Z")

</div>

Hi smckdwn16, the `comparable` interface only provides the operators `=` and `<>` (inequality) see; [comparable documentation](https://dev.epicgames.com/documentation/en-us/uefn/comparable-in-verse) , lesser and greater comparison is only available for `int` and `float` which do not share a common interface (although I hope in the future we have a “magnitudable” type or trait for such a purpose)

---

<div class="post-metadata">

**Author:** ![smckdwn16](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smckdwn16](https://forums.unrealengine.com/u/smckdwn16)\
**Post date:** [August 21, 2024, 3:49pm UTC](https://forums.unrealengine.com/t/issue-with-type-inference-in-verse-generics/1979759/3 "2024-08-21T15:49:03Z")

</div>

Hi Noldstein. Thanks for the response.

The issue isn’t that an interface is missing. It’s that the compiler isn’t inferring the type correctly imo.

For instance: `var Element: t = Array[0]` should be inferred as type `int` if an int array is passed in. If `Element` is then compared to other elements in that same array, the types should be inferred correctly.

However, I do see how a magnitudable trait would be beneficial.

---

<div class="post-metadata">

**Author:** ![smckdwn16](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smckdwn16](https://forums.unrealengine.com/u/smckdwn16)\
**Post date:** [August 21, 2024, 7:59pm UTC](https://forums.unrealengine.com/t/issue-with-type-inference-in-verse-generics/1979759/4 "2024-08-21T19:59:35Z")

</div>

Thought about this more and realized you are correct. There needs to be an interface for this similar to the `PartialOrd` trait in Rust.
