如何在榆树中制作一组独特的记录

问题描述 投票:4回答:1

我需要一组独特的记录。但是Elm Core的Set将集合成员限制为comparable

import Set exposing (Set)

mySet = Set.empty
Set.insert {name="Foo"} mySet
-- TYPE MISMATCH ----------------------------------------------------------- elm

The 1st argument to `insert` is not what I expect:

6|   Set.insert {name="Foo"} mySet
                ^^^^^^^^^^^^
This argument is a record of type:

    { name : String }

But `insert` needs the 1st argument to be:

    comparable

Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.

你如何在榆树制作一套唱片?

elm
1个回答
5
投票

使用标准库,您不能。如“提示”中所述,您可以使用元组,但这些仅限于0.19中的3元组。

所以,我认为你最好的选择是使用https://package.elm-lang.org/packages/Gizra/elm-all-set/latest/EverySet

© www.soinside.com 2019 - 2024. All rights reserved.