:ハスケルIは、以下の構造を有する新しい演算子を作成し、制御誤差
テラ[[ '0'、 '1'、 '0'、 '1']、[ '0'、 '1'、 '0'、 '1']、[ '1'、 '0'、 'G'、 '1']
およびDE機能:
esTerra:: Taulell -> (Int,Int) -> Bool
esTerra t (u,d) =
case t!!!u!!!d of
Left e -> False
Right p -> True
(!!!) :: [a] -> Int -> Either Bool a
xs !!! n | n < 0 = Left False -- error Exception: Prelude.!!:...
[] !!! _ = Left False -- error Exception: Prelude.!!:...
(x:_) !!! 0 = Right x
(_:xs) !!! n = xs!!!(n-1)
機能!操作と同じです!あなたがエラーメッセージを返すために持っているときが、偽
が、リターンエラーを返します。
Couldn't match expected type ‘[a0]’
with actual type ‘Either Bool [Char]’
In the first argument of ‘(!!!)’, namely ‘t !!! u’
In the expression: t !!! u !!! d
In the expression:
case t !!! u !!! d of {
Left e -> False
Right p -> True }
から?
感謝の
あなたの 'Either Bool a'は決して' Left True'を使うことはないので、 'Maybe a'を使うのと同じです。もしあなたの選択が' Either'ならば 'Either String'を使うことをお勧めします。 'Left'を使い、' Left 'という説明的なエラーメッセージ " – epsilonhalbe