google-research / dex-lang

Research language for array processing in the Haskell/ML family
BSD 3-Clause "New" or "Revised" License
1.58k stars 106 forks source link

Can't negate a `Float64` #1345

Open ararslan opened 9 months ago

ararslan commented 9 months ago
>=> -f_to_f64(1.0)
> Type error: can't synthesize a class dictionary for: (VSpace Float64)

This appears to be because there are no Float64 literals and unary - falls back to calling neg, which is only defined for VSpace, and there is no VSpace instance for Float64. I think this should be fixable by defining

instance VSpace(Float64)
  def (.*)(x, y) = x * y

alongside the current instance for Float (AKA Float32).

ararslan commented 9 months ago

Actually, it seems a bit odd that sign flipping requires multiplication; perhaps it would suffice for neg to be defined instead as:

def neg(x:a) -> a given (a|Sub) = (zero::a) - x

?