Enum arithmetic_typing::defs::Prelude
source · #[non_exhaustive]pub enum Prelude {
False,
True,
If,
While,
Defer,
Map,
Filter,
Fold,
Push,
Merge,
All,
Any,
}
Expand description
Map containing type definitions for all variables from Prelude
in the eval crate.
§Contents
true
andfalse
Boolean constantsif
,while
,map
,filter
,fold
,push
andmerge
functions
The merge
function has somewhat imprecise typing; its return value is
a dynamically-sized slice.
The array
function is available separately via Self::array()
.
§Examples
Function counting number of zeros in a slice:
use arithmetic_parser::grammars::{F32Grammar, Parse};
use arithmetic_typing::{defs::Prelude, Annotated, TypeEnvironment, Type};
let code = "|xs| xs.fold(0, |acc, x| if(x == 0, acc + 1, acc))";
let ast = Annotated::<F32Grammar>::parse_statements(code)?;
let mut env: TypeEnvironment = Prelude::iter().collect();
let count_zeros_fn = env.process_statements(&ast)?;
assert_eq!(count_zeros_fn.to_string(), "([Num; N]) -> Num");
Limitations of merge
:
let code = "
len = |xs| xs.fold(0, |acc, _| acc + 1);
slice = (1, 2).merge((3, 4));
slice.len(); // methods working on slices are applicable
(_, _, _, z) = slice; // but destructuring is not
";
let ast = Annotated::<F32Grammar>::parse_statements(code)?;
let mut env: TypeEnvironment = Prelude::iter().collect();
let errors = env.process_statements(&ast).unwrap_err();
assert_eq!(errors.len(), 1);
let err = errors.iter().next().unwrap();
assert_eq!(err.main_location().span(code), "(_, _, _, z)");
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
False
false
type (Boolean).
True
true
type (Boolean).
If
Type of the if
function.
While
Type of the while
function.
Defer
Type of the defer
function.
Map
Type of the map
function.
Filter
Type of the filter
function.
Fold
Type of the fold
function.
Push
Type of the push
function.
Merge
Type of the merge
function.
All
Type of the all
function.
Any
Type of the any
function.
Implementations§
source§impl Prelude
impl Prelude
sourcepub fn array<T: PrimitiveType>(index_type: T) -> Function<T>
pub fn array<T: PrimitiveType>(index_type: T) -> Function<T>
Returns the type of the array
generation function from the eval crate.
The array
function is not included into Self::iter()
because in the general case
we don’t know the type of indexes.
Trait Implementations§
source§impl PartialEq for Prelude
impl PartialEq for Prelude
impl Copy for Prelude
impl Eq for Prelude
impl StructuralPartialEq for Prelude
Auto Trait Implementations§
impl Freeze for Prelude
impl RefUnwindSafe for Prelude
impl Send for Prelude
impl Sync for Prelude
impl Unpin for Prelude
impl UnwindSafe for Prelude
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)