Skip to content

Implicitly chain conversion factors #50

@zainab-ali

Description

@zainab-ali

Given an implicit ConversionFactor[P, Q, A, B] and a ConversionFactor[P, Q, B, C], create a ConversionFactor[P, Q, A, C].

Where there are multiple units for a single dimension, conversion factors need to be defined between each pair individually. This means that there's a matrix of implicit conversion factors that need to be written. E.g. for degree, arcsecond and arcminute, conversion factors need to be written for arcsecond - arcminute, arcminute - degree and arcsecond - degree.

It should technically be possible to implicitly derive the arcsecond - degree conversion using the previous two. This would remove a lot of boilerplate when adding new units.

The following implicit fails to resolve:

implicit def failedAttemptAtChaining[P, Q, A, B](implicit ab: ConversionFactor[P, Q, A, B], bc: ConversionFactor[P, Q, B, C]): ConversionFactor[P, Q, A, C] = ???

This is probably because the compiler cannot resolve B, as it only knows A and C.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions