【发布时间】:2012-01-13 16:32:14
【问题描述】:
试图在 Haskell 中抛出异常:
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'
我该如何解决?
你能不能写下我在调用测试函数时如何捕捉到这样的异常?
【问题讨论】:
标签: haskell