How to resolve the algorithm Singly-linked list/Element definition step by step in the ATS programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Singly-linked list/Element definition step by step in the ATS programming language

Table of Contents

Problem Statement

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Singly-linked list/Element definition step by step in the ATS programming language

Source code in the ats programming language

(* The Rosetta Code linear list type can contain any vt@ype.
   (The ‘@’ means it doesn’t have to be the size of a pointer.
   You can read {0 <= n} as ‘for all non-negative n’. *)
dataviewtype rclist_vt (vt : vt@ype+, n : int) =
| rclist_vt_nil (vt, 0)
| {0 <= n} rclist_vt_cons (vt, n + 1) of (vt, rclist_vt (vt, n))

(* A lemma one will need: lists never have negative lengths. *)
extern prfun {vt : vt@ype}
lemma_rclist_vt_param
          {n : int}
          (lst : !rclist_vt (vt, n)) : [0 <= n] void

(* Proof of the lemma. *)
primplement {vt}
lemma_rclist_vt_param lst =
  case+ lst of
  | rclist_vt_nil () => ()
  | rclist_vt_cons _ => ()

  

You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Ada programming language
You may also check:How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Mathcad programming language
You may also check:How to resolve the algorithm Descending primes step by step in the Delphi programming language
You may also check:How to resolve the algorithm Terminal control/Cursor positioning step by step in the COBOL programming language
You may also check:How to resolve the algorithm Average loop length step by step in the Python programming language