Skip to content
Snippets Groups Projects
Commit 7f4bd5d1 authored by Maxime Jacquemin's avatar Maxime Jacquemin Committed by David Bühler
Browse files

[Kernel] Comments about complexity and behavior of Nat and Finite functions

parent 028c7273
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,6 @@ open Types ...@@ -30,7 +30,6 @@ open Types
let first : type n. n succ finite = 0 let first : type n. n succ finite = 0
let next : type n. n finite -> n succ finite = fun n -> n + 1 let next : type n. n finite -> n succ finite = fun n -> n + 1
let weaken : type n. n finite -> n succ finite = fun n -> n
let ( == ) : type n. n finite -> n finite -> bool = fun l r -> l = r let ( == ) : type n. n finite -> n finite -> bool = fun l r -> l = r
let to_int : type n. n finite -> int = fun n -> n let to_int : type n. n finite -> int = fun n -> n
......
...@@ -23,14 +23,22 @@ ...@@ -23,14 +23,22 @@
open Nat.Types open Nat.Types
module Types : sig type 'n finite end module Types : sig type 'n finite end
open Types open Types
val first : 'n succ finite val first : 'n succ finite
val next : 'n finite -> 'n succ finite val next : 'n finite -> 'n succ finite
val ( == ) : 'n finite -> 'n finite -> bool val ( == ) : 'n finite -> 'n finite -> bool
val weaken : 'n finite -> 'n succ finite (* The call [of_int limit n] returns a finite value representing the n-nd
element of a finite set of cardinal limit. If n is strictly negative then it
returns the first element. If n is greater or equal to the limit then it
returns the last element. This function complexity is O(1). *)
val of_int : 'n succ nat -> int -> 'n succ finite val of_int : 'n succ nat -> int -> 'n succ finite
(* The call [to_int n] returns an integer equal to n. This function complexity
is O(1). *)
val to_int : 'n finite -> int val to_int : 'n finite -> int
(* The call [for_each acc limit f] folds over each finite elements of a set of
cardinal limit, computing f at each step. The function complexity is O(n). *)
val for_each : 'a -> 'n nat -> ('n finite -> 'a -> 'a) -> 'a val for_each : 'a -> 'n nat -> ('n finite -> 'a -> 'a) -> 'a
...@@ -34,6 +34,15 @@ val zero : zero nat ...@@ -34,6 +34,15 @@ val zero : zero nat
val one : zero succ nat val one : zero succ nat
val succ : 'n nat -> 'n succ nat val succ : 'n nat -> 'n succ nat
val prev : 'n succ nat -> 'n nat val prev : 'n succ nat -> 'n nat
(* The call [to_int n] returns an integer equal to n. This function complexity
is O(1). *)
val to_int : 'n nat -> int val to_int : 'n nat -> int
(* Returns a positive or null natural. If the given parameter is stricly
negative then 0 is returned. This function complexity is O(n). *)
val of_int : int -> positive_or_null val of_int : int -> positive_or_null
(* Returns a strictly positive natural. If the given parameter is less or equal
than zero, then 1 is returned. This function complexity is O(n). *)
val of_strictly_positive_int : int -> strictly_positive val of_strictly_positive_int : int -> strictly_positive
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment