Умножение сложного двойника на двойник в Haskell

Я был немного удивлен, когда следующий код не компилировался:

-- Code 1
import Complex
type Velocity = Complex Double
type Force = Complex Double
type FrictionCoeff = Double

frictionForce :: FrictionCoeff -> Velocity -> Force
frictionForce mu vel = mu * vel

Ошибка гласит

Couldn't match expected type `Complex Double'
            with actual type `Double'
Expected type: Force
Actual type: FrictionCoeff
In the first argument of `(*)', namely `mu'
In the expression: mu * vel

Итак, вкратце

-- Code 2
let z = 1 :+ 2
z * 3     -- Goes fine.
z * 2.5   -- Goes fine.
z * (2.5 :: Double)  -- Explodes.

Комплекс определяет (*) как

instance  (RealFloat a) => Num (Complex a)  where
    (x:+y) * (x':+y') =  (x*x'-y*y') :+ (x*y'+y*x')

Почему 3 (Число a => a) и 2.5 (Дробное число a => a) могут быть сопоставлены с образцом (x:+y), а Double не может ?

7
задан Niriel 28 March 2012 в 11:56
поделиться