Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
57af3d95
Commit
57af3d95
authored
Aug 03, 2011
by
Jean-Christophe Filliâtre
Browse files
list: theories FoldLeft and FoldRight
parent
058303ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
theories/list.why
View file @
57af3d95
...
@@ -15,7 +15,7 @@ theory Length
...
@@ -15,7 +15,7 @@ theory Length
| Cons _ r -> 1 + length r
| Cons _ r -> 1 + length r
end
end
lemma Length_nonnegative: forall l: list 'a. length
(l)
>= 0
lemma Length_nonnegative: forall l: list 'a. length
l
>= 0
lemma Length_nil: forall l: list 'a. length l = 0 <-> l = Nil
lemma Length_nil: forall l: list 'a. length l = 0 <-> l = Nil
...
@@ -246,16 +246,39 @@ theory Map
...
@@ -246,16 +246,39 @@ theory Map
type b
type b
function f a : b
function f a : b
function map(l: list a) : list b =
function map
(l: list a) : list b =
match l with
match l with
| Nil -> Nil
| Nil -> Nil
| Cons x r -> Cons (f x) (map r)
| Cons x r -> Cons (f x) (map r)
end
end
end
theory FoldLeft
use import List
type a
type b
function f b a : b
function fold_left (acc: b) (l: list a) : b =
match l with
| Nil -> acc
| Cons x r -> fold_left (f acc x) r
end
end
end
theory Fold
theory FoldRight
(* TODO (a la Map) *)
use import List
type a
type b
function f a b : b
function fold_right (l: list a) (acc: b) : b =
match l with
| Nil -> acc
| Cons x r -> f x (fold_right r acc)
end
end
end
theory ListRich
theory ListRich
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment