:ハスケルで投げる例外と-XDeriveDataTypeable
import Control.Exception
import Data.Typeable
data MyException = ThisException | ThatException deriving (Show, Typeable)
instance Exception MyException
data CellPos = CellPos Int Int deriving (Show, Read)
test :: String -> IO CellPos
test str = do
{
if length str == 0
then
throw ThisException;
else
return (CellPos 0 0);
}
コンパイラは言う:
Can't make a derived instance of `Typeable MyException':
You need -XDeriveDataTypeable to derive an instance for this class
In the data type declaration for `MyException'
私はそれを解決することができますか?
test関数を呼び出すときに、どのようにそのような例外をキャッチすることができますか?
ありがとう、あなた!また、テスト関数を呼び出すときにそのような例外をどのように捕らえることができますか? – user606521
@ user606521:確か;私は例で私の答えを更新しました。 – ehird