我无法确定我为什么会得到***例外:堆栈溢出

问题描述 投票:2回答:1

我正在编写调用其他函数的函数。一切都很好,直到我发表评论--A6 AGP(t)。当我尝试运行agp1时会抛出***异常:堆栈溢出。

我已经尝试添加和删除括号,以便不会一次又一次地调用函数,但仍然没有运气。

import Data.List
import System.IO

p = 1.50
dt= 0.050
at = 0.075
wMax = 20.00
da1 = 300.0
dcasa = 0.05
dSort = 1.50
dKafv = 0.50
aa1 = 250.0
acasa = 0.05
aKafv = 0.25
aSort = 1.00
v = 1200.0
l = 47490.0


--A1 AGL(t)
agl :: Float -> Float
agl a = a + 5

--A6 AGP(t)
agp :: Float -> Float
agp x = (agp (x-1) - ((at - agp (x-1)) / at)) * (atl (x-1) - at)

agp1 =  agp 2.0

--A7 ATL(t)
atl :: Float -> Float
atl x = (agl x - agl (x+1)) / agl (x)

--A10 DCAS(t)
dcas :: Float -> Float
dcas x = (l/v)*da1*((1.0-dcasa)**(dSort*(x - 1)))*dKafv*(((1 - ((1- 
         dcasa)**(dSort+1))) / dcasa) - 1)


--A11 ACAS(t)
acas :: Float -> Float
acas x = (l/v)*aa1*((1.0-acasa)**(aSort*(x - 1)))*aKafv*(((1 - ((1- 
          acasa)**(aSort+1))) / acasa) - 1)

--A12 Da(t)
da :: Float -> Float
da x = da1 * ((1.0 - dcasa) ** (dSort * (x - 1)))


--A13 Aa(t)
aa :: Float -> Float
aa x = aa1 * ((1.0 - acasa) ** (x - 1))
haskell haskell-stack
1个回答
0
投票

您需要一些基本情况,其中agp不会调用自身,因此计算结束。我的意思是你的功能必须是这样的:

--A6 AGP(t)
agp :: Float -> Float
agp x
    | agp' > 0 = agp'
    | otherwise = 0
    where agp' = (agp (x-1) - ((at - agp (x-1)) / at)) * (atl (x-1) - at)
© www.soinside.com 2019 - 2024. All rights reserved.