Can Haskell functions be proved/model-checked/verified with correctness properties?

后端 未结 11 1103
挽巷
挽巷 2021-01-29 18:46

Continuing on from ideas in: Are there any provable real-world languages?

I don\'t know about you, but I\'m sick of writing code that I can\'t guarantee.

相关标签:
11条回答
  • 2021-01-29 18:53

    Your seemingly simple example, add(a,b), is actually difficult to verify - floating point, overflow, underflow, interrupts, is the compiler verified, is the hardware verified, etc.

    Habit is a simplified dialect of Haskell that allows for proving program properties.

    Hume is a language with 5 levels, each more limitedand therefore easier to verify:

    Full Hume
      Full recursion
    PR−Hume
      Primitive Recursive functions
    Template−Hume
      Predefined higher−order functions
      Inductive data structures
      Inductive  Non−recursive first−order functions
    FSM−Hume
      Non−recursive data structures
    HW−Hume
      No functions
      Non−recursive data structures
    

    Of course, the most popular method today for proving program properties is unit testing, which provides strong theorems, but these theorems are overly specific. "Types Considered Harmful", Pierce, slide 66

    0 讨论(0)
  • 2021-01-29 18:54

    It's certainly possible to prove some properties of Haskell programs formally. I've had to do so at my FP exam: given two expressions, prove that they denote the same function. It's not possible to do this in general since Haskell is Turing-complete, so any mechanical prover would either have to be a proof assistant (semi-automatic with user guidance) or a model checker.

    There have been attempts in this direction, see e.g. P-logic: property verification for Haskell programs or Proving the correctness of functional programs using Mizar. Both are academic papers describing methods more than implementations.

    0 讨论(0)
  • 2021-01-29 18:55

    Have you had a look at quickcheck? It may offer some of the things you need.

    http://www.haskell.org/haskellwiki/Introduction_to_QuickCheck

    0 讨论(0)
  • 2021-01-29 18:59

    The tool AProVE is (at least) able to prove termination of Haskell programs, which is part of proving correctness. More information can be found in this paper (shorter version).

    Apart from that, you might be interested in Dependent Types. Here, the type system is extended and used to make wrong programs impossible.

    0 讨论(0)
  • 2021-01-29 19:02

    Some very recent effort by MSR Cambridge: http://research.microsoft.com/en-us/um/people/simonpj/papers/verify/hcc-popl.pdf

    0 讨论(0)
  • 2021-01-29 19:03

    Sounds like you want ESC/Haskell: http://research.microsoft.com/en-us/um/people/simonpj/papers/verify/index.htm

    Oh, and Agda now does have a web framework (proof of concept, at least): http://www.reddit.com/r/haskell/comments/d8dck/lemmachine_a_web_framework_in_agda/

    0 讨论(0)
提交回复
热议问题