Is it possible to define a function on only one variant of a type?

See also this post discussing how record and custom types can be modelled using math (its not hard):

Pulling out the common fields is akin to extracting a common factor from some expression. I tend to think of product-sum-product form with all common fields pulled to the outer product as what you are generally aiming for.

This is in product-sum-product form:

-- Outer product
type alias MyType =
  { common1 : ...
  , common2 : ...
  , specific : Specific
  }

-- Sum
type Specific
  = Variant1 { field1 : ..., field2 : ... } -- Inner Product
  | Variant2 { field3 : ... } -- Inner Product
1 Like