Numeric type defaulting

Numeric literals with a decimal point are ambiguous since the scale isn’t specified. In most cases I’d like to default to Decimal when applying a polymorphic function to such literals, is there a more concise way then just specializing identity (explicit type annotations are more verbose):

dec : Decimal -> Decimal
dec = identity

f (dec 1.1) (dec 2.2)

Haskell has default declarations, but those don’t appear to be supported in Daml.

Hi @asarpeshkar,

Daml doesn’t support defaulting for numeric literals. The approach you showed is a good one. The more common solution is to use type annotations (which are a bit more verbose, like you said):

f (1.1 : Decimal) (2.2 : Decimal)

We don’t have defaults in daml because we don’t want daml developers to accidentally use the wrong level of precision & start getting unexpected results. In practice the lack of defaults isn’t a big issue because the type checker can infer the precision in a lot of cases (like when you used dec here, for example). In cases where the type checker can’t infer it, you do need to supply the precision via a type annotation.

1 Like