拋出異常試圖拋出一個異常哈斯克爾:在Haskell和-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'
我怎樣才能解決這個問題?
你還可以寫我如何在調用測試函數時捕獲這樣的異常嗎?
謝謝你的男人!你還可以寫我如何在調用測試函數時捕獲這樣的異常? – user606521 2012-01-13 17:00:24
@ user606521:好的;我用一個例子更新了我的答案。 – ehird 2012-01-13 17:07:12