0
我定義了一個在哪裏定義名稱earthSecondsAYear。可悲的是,它無法在前面的where子句的範圍內。秒其中名稱不在前面範圍內
下面是代碼:
module SpaceAge (Planet(..), ageOn) where
data Planet = Mercury
| Venus
| Earth
| Mars
| Jupiter
| Saturn
| Uranus
| Neptune
ageOn :: Planet -> Float -> Float
ageOn planet seconds = (seconds/100) * planetYearSecs planet
where planetYearSecs Mercury = (earthSecondsAYear/100) * 0.2408
planetYearSecs Venus = 0.6151
planetYearSecs Mars = 1.8808
planetYearSecs Jupiter = 11.8626
planetYearSecs Saturn = 29.4474
planetYearSecs Uranus = 84.0168
planetYearSecs Neptune = 164.7913
planetYearSecs Earth = 100
where earthSecondsAYear = 31557600
錯誤消息:
:14:34: error:
Variable not in scope: earthSecondsAYear
我缺少什麼?
'where'只適用於它上面的定義(所以'planetYearSecs Earth = 100')。這一直咬着我。 :) – Alec