Accessing values in custom types

I’m wondering if there’s a way to get values out of a custom type, in an example similar to the following, without using a case switch. Wondering if I’m missing something obvious.

type A = A Int Int

getFirst : A -> Int
getFirst a =
    case A of
        A x _ -> x

I know that the above would be better modeled as a tuple, and a record would do as well, but this is just a trite example to help illustrate my question.

If your type only has one variant* you can do it like this:

type A = A Int Int

getFirst : A -> Int
getFirst (A x _) =
    x

* More precisely, if your pattern is exhaustive.

3 Likes

Exactly what I was looking for — thank you!

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