English 中文(简体)
Haskell“例外”
原标题:Haskell "exceptions"

我拿着一套用户、群体以及用户和群体之间的绘图。 我有各种功能操纵这些设备,但不能增加一个用户配对器;对一个没有用户的用户进行组群测绘,也不能排除一个仍然有用户作为成员的群体等。

因此,我基本上希望这些职能屈服于呼吁者必须明确处理的“例外”。

我首先想回到这样的东西:

data Return r e = Success r | Exception e

如果打电话者没有与<>Exception<>t/code>匹配,他们希望能收到编辑警告,或者至少在存在问题时有明显的操作错误。

这是最佳办法,是否有事先包装的解决办法? 请注意,我需要在纯粹的法典中,而不是在IO Monad中 throw取“例外”。

最佳回答
问题回答

<代码>Return r e, 您描述的正是标准类型。

data Either a b = Left a | Right b

You might want to use the so called "error monad" (a more suitable name is "exception monad") of the mtl package. (Alternatively, there s ExceptionT in the monadLib package if you don t want to use mtl.) This allows you to do error handling in pure code by invoking throwError and catchError. Here you can find an example that shows how to use it.





相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...