Created
April 22, 2018 18:35
-
-
Save graydon/901f98049d05db65d9a50f741c7f7626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open FStar.Char | |
open FStar.Seq | |
(* Helper *) | |
let max a b = if a > b then a else b | |
(* Definition *) | |
let leftpad (c:char) (n:nat) (s:seq char) : seq char = | |
let pad = max (n - length s) 0 in | |
append (create pad c) s | |
(* Spec and verification *) | |
let leftpad_correct (c:char) (n:nat) (s:seq char) = | |
let r = leftpad c n s in | |
(* Two abbreviations to make conditions more legible *) | |
let ssz = length s in | |
let pad = max (n - ssz) 0 in | |
(* These are all statically discharged *) | |
let _ = assert (length r = max n ssz) in | |
let _ = assert (forall (i:nat). i < n - ssz ==> index r i = c) in | |
let _ = assert (forall (i:nat). i < ssz ==> index r (pad + i) = index s i) in | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment