2
以下に出力を示します。私は数値のリストを与え、それらが等しくなければFalseを返し、正しく働いています。しかし、数字のリストが等しいならば、それは真を返さない。このコードをチェックできますか?各数字のリストは等しくない偽ではあるが同じ数字では動作しない
la [] = True
la a =
if ((head a)==head (tail a))
then la (tail a)
else False
出力:
Cw2016> la [1,2,2]
False
Cw2016> la [2,2,2]
Program error: pattern match failure: head []
Cw2016> la [2,2,3]
False
Cw2016> la [0,1,3]
False
Cw2016> la [0,0,3]
False
Cw2016> la [0,0,0]
Program error: pattern match failure: head []
Cw2016>
'la [1]'の評価を行います。 –
'head(x:xs)= x'と' tail(x:xs)= xs'は 'la(x:xs)'と読みやすくなりました。 – wizzup