comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Implicit actions & program correctness
Date: Mon, 25 May 2020 23:36:31 +0300
Date: 2020-05-25T23:36:31+03:00	[thread overview]
Message-ID: <hj2oigFohdmU1@mid.individual.net> (raw)
In-Reply-To: <14afb70d-cb70-4ca2-bd24-f9d9664ee103@googlegroups.com>

On 2020-05-25 23:15, deadhacker wrote:
> On Friday, May 15, 2020 at 3:10:02 PM UTC-7, Paul Rubin wrote:
>> You might like this article (not Ada specific):
>> 
>> http://blog.tmorris.net/posts/understanding-practical-api-design-static-typing-and-functional-programming/
>
>> 
> Paul, thank you so much for the link.  It's good reading.
> 
> To me, seems that his third requirement is the tough one.  (Quoting
> it here: "If I call move on a tic-tac-toe board, but the game has
> finished, I should get a compile-time type-error. In other words,
> calling move on inappropriate game states (i.e. move doesn’t make
> sense) is disallowed by the types.")
> 
> It seems that if I have a Move subprogram that operates on a Game, it
> & produces another Game, I don't see how it could sometimes return a
> FinishedGame that can be detected at compile-time.  (It could return
> a Game that could be checked for Finished at run-time.)
> 
> Sadly, his Java API is no longer available, so I can't see how he
> solved it.
> 
> Do you (or anyone else here) know how it could be solved with Ada?

Checking such things was (and is) the goal of "typestate analysis", 
https://en.wikipedia.org/wiki/Typestate_analysis.

In Ada, it could be done statically with the precondition/postcondition 
system, plus some program proof. The Move operation would have a 
precondition "not Finished (Game)", and the prover would check that the 
program flow after any call of Move always ensures this precondition 
before Move is called again. Presumably this would be done by the 
program inspecting Finished (Game) in a control-flow condition, and 
allowing flow to a new Move call only in the "not finished" case.

Making this check "at compile-time" would of course require that the 
prover is always executed in or after any compilation.

-- 
Niklas Holsti
niklas holsti tidorum fi
       .      @       .

  reply	other threads:[~2020-05-25 20:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 17:45 Implicit actions & program correctness deadhacker
2020-05-15 17:55 ` deadhacker
2020-05-15 18:27 ` Nasser M. Abbasi
2020-05-15 19:01 ` Paul Rubin
2020-05-15 19:03 ` Jeffrey R. Carter
2020-05-15 20:13   ` deadhacker
2020-05-15 22:09     ` Paul Rubin
2020-05-25 20:15       ` deadhacker
2020-05-25 20:36         ` Niklas Holsti [this message]
2020-05-25 22:31         ` Paul Rubin
2020-05-26  8:47           ` Niklas Holsti
2020-05-26  9:55             ` Paul Rubin
2020-05-16 13:52     ` Brian Drummond
2020-05-16 10:10 ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox