Newtype deriving `comparable`

If I define an opaque type, for instance:

type Identifier = Identifier String

Is there a way to make this comparable, so I can use it as a dict key?

Unfortunately no.
As far as I know, you can either use a library like AnyDict, or manage it yourself in some way

type Identifier = Identifier String

toString : Identifier -> String
toString (Identifier str) =
    str

-- or

compareIdentifiers : Identifier -> Identifier -> Order
compareIdentifiers (Identifier id1) (Identifier id2) =
    compare id1 id2

-- or

wrap : String -> Identifier
wrap =
    Identifier


unwrap : Identifier -> String
unwrap (Identifier str) =
    str
2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.