简体   繁体   English

用于测试Functors,Applicatives和Monads的工具?

[英]Tools for testing Functors, Applicatives and Monads?

I have created a type which implements Functor, Applicative and Monad. 我创建了一个实现Functor,Applicative和Monad的类型。 I wanted to verify that they follow the laws of each. 我想验证他们是否遵守每个法律。 But upon trying to do this manually, it turned into a daunting and quite difficult task. 但是在尝试手动执行此操作时,它变成了一项艰巨而艰巨的任务。

So, what I am wondering is: 所以,我想知道的是:

How can I automatically test that the laws of each class are properly implemented? 如何自动测试每个班级的法律是否正确实施?

But upon trying to do this manually, it turned into a daunting and quite difficult task. 但是在尝试手动执行此操作时,它变成了一项艰巨而艰巨的任务。

One way is to state your laws in a language like Coq and formally prove them. 一种方法是用Coq这样的语言陈述你的法律并正式证明它们。 For example, John Wiegley proved pipes law in Coq. 例如,John Wiegley在Coq中证明了管道法

How can I automatically test that the laws of each class are properly implemented? 如何自动测试每个班级的法律是否正确实施?

You cannot get a strong guarantee unless you prove them. 除非你证明,否则你无法得到有力的保证。 Maybe you can check their property using a library like Quickcheck . 也许你可以使用像Quickcheck这样的库检查他们的财产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM