val buffer (dest: Type u#a) : Type u#(max 1 a)
val buffer (dest: Type u#a) : Type u#(max 1 a)
let buffer (dest:Type u#a) : Type u#(max 1 a) = (src:Type0 & rrel:B.srel src & rel:B.srel src & buffer_view src rrel rel dest)
(*
   Copyright 2008-2018 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)
module LowStar.BufferView.Down

(**
 * A "down view" on a buffer allows treating a
 * `Buffer.buffer a` as a
 * `BufferView.Down.buffer b`
 *
 * A "view" on a buffer is intended for specification purposes only
 * It does not correspond to a pointer cast in C.
 *
 * Building a down view requires providing a pair of mutually inverse functions
 * from `a` to sequences of `b`. (e.g., from a `lbuffer u32 n` to a `lbuffer u8 (4*n)`)
 *
 * I.e., a down view allows "exploding" an `a` into its component `b`'s.

 * In contrast, an "up view" (see LowStar.BufferView.Up) allows
 * "compacting" a sequences of `a`'s into a `b`.
 * (e.g., from an `lbuffer u8 (4*n)` to an `lbuffer u32 n`)
 **)
 
open LowStar.Monotonic.Buffer
open FStar.Mul
module HS=FStar.HyperStack
module B=LowStar.Monotonic.Buffer

(** Definition of a view **)

/// `f` and `g` are mutual inverses
let inverses #a #b
             (f: (a -> GTot b))
             (g: (b -> GTot a)) =
  (forall x. g (f x) == x) /\
  (forall y. f (g y) == y)

/// `view a b` maps single `a`'s to an `n`-lengthed sequence of `b`s
noeq
type view (a:Type) (b:Type) =
  | View : n:pos ->
           get:(a -> GTot (Seq.lseq b n)) ->
           put:(Seq.lseq b n -> GTot a) {
             inverses get put
           } ->
           view a b

/// `buffer_views src dest`:
///
/// The main abstract type provided by this module. This type is
/// indexed by both the `src` and `dest` types. The former (`src`) is
/// the type of the underlying B.buffer's contents: as such, it is
/// forced to be in universe 0.
///
/// The destination type `dest` is for specification only and is not
/// subject to the same universe constraints by the memory model.
///

val buffer_view (src:Type0) (rrel rel:B.srel src) (dest:Type u#b) : Type u#b

/// `buffer b`: In contrast to `buffer_view`, `buffer b` hides the
/// source type of the view. As such, it is likely more convenient to
/// use in specifications and the rest of this interface is designed
/// around this type.
///
/// However, the type lives in a higher universe,
/// this means, for instance, that values of `buffer b` cannot be
/// stored in the heap.
///
/// We leave its definition transparent in case clients wish to
/// manipulate both the `src` and `dest` types explicitly (e.g., to
/// stay in a lower universe)
/
prims.fst.checked LowStar.Monotonic.Buffer.fsti.checked FStar.Seq.fst.checked FStar.Pervasives.fsti.checked FStar.Mul.fst.checked FStar.HyperStack.ST.fsti.checked FStar.HyperStack.fst.checked
LowStar.BufferView.Down.fsti
dest: Type -> Type
FStar.Pervasives.dtuple4 LowStar.Monotonic.Buffer.srel LowStar.BufferView.Down.buffer_view
let buffer (dest: Type u#a) : Type u#(max 1 a) =
  
(src: Type0 & rrel: B.srel src & rel: B.srel src & buffer_view src rrel rel dest)