我已经找了很长一段时间了,但没有找到任何答案。我试着编写一个函数,根据它是否在圈年返回特定月份的天数。我之前已经定义了“翻版年”这个函数。我的问题是如何在另一个If条件中创建一个If条件?
非常感谢你的回答:)
lapyear:: Int->Bool
lapyear a
|((rem)a 400)==0 = True
|((rem)a 100)==0 = False
|((rem)a 4)==0 = True
|otherwise = False
type Mes = Int
type Anyo = Int
type Dias= Int
daysAmonth:: Mes->Anyo->Dias
daysAmonth mes anyo
if lapyear anyo then do
|or[mes==01,mes==03,mes==05,mes==07,mes==08,mes==10,mes==12] = 31
|mes==02 = 29
|otherwise = 30
else
|or[mes==01,mes==03,mes==05,mes==07,mes==08,mes==10,mes==12] = 31
|mes==02 = 28
|otherwise = 30
发布于 2015-11-03 21:56:12
您可能会喜欢MultiWayIf
扩展。
{-# LANGUAGE MultiWayIf #-}
if lapyear anyo then if
| or [...] -> 31
| mes == 20 -> 29
| otherwise -> 30
else if
| ...
发布于 2015-11-04 08:58:16
Haskell平原的一些替代方案(没有扩展):
if then else
链:
如果哪一年的话如果或者..。如果mes == 02那么29其他30 .let
:
如果年份为任意,则让结果@或.= 31 _ == _case
:
如果年份为任意,则用_我相信最后一个是最受欢迎的。
https://stackoverflow.com/questions/33509676
复制相似问题