Crates.io | mathelogos |
lib.rs | mathelogos |
version | 0.1.1 |
source | src |
created_at | 2024-05-18 18:54:40.87078 |
updated_at | 2024-05-18 19:00:01.525728 |
description | Library to make Rust as a functional programming language. |
homepage | |
repository | https://github.com/ladroid/Mathelogos |
max_upload_size | |
id | 1244450 |
size | 23,608 |
The Mathelogos library is designed to introduce functional programming constructs to Rust, a language traditionally known for its systems programming capabilities and performance. By leveraging macros, Mathelogos mimics the expressiveness and conciseness of a functional language like Haskell within the Rust ecosystem. This document explains the functional constructs provided by Mathelogos, compares them with their Haskell counterparts, and elaborates on the motivation and goals of this library.
The primary goal of Mathelogos is to facilitate functional programming paradigms in Rust, enhancing the language's capabilities for developers familiar with functional programming. This includes introducing concepts like higher-order functions, lazy evaluation, and monads in a way that integrates seamlessly with Rust's own features like ownership and type safety. By doing so, Mathelogos aims to combine Rust's performance and safety with the expressive power of functional programming.
Mathelogos introduces several macros to emulate functional programming constructs:
map
.foldl
.filter
.foldl
but often referred to as reduce
in other languages.To illustrate the usage of Mathelogos and its comparison with Haskell, consider the following examples:
Rust with Mathelogos:
let lambda_example = lambda!(x, y => x + y);
let add_two_and_mul_by_three = compose!(|x| mul(x, 3), |x| add(x, 2));
Haskell:
lambdaExample = \x y -> x + y
addTwoAndMulByThree = (\x -> mul x 3) . (\x -> add x 2)
Rust with Mathelogos:
let squared_numbers = map!(|&x| x * x, &numbers);
let sum = foldl!(|acc, &x| acc + x, 0, &numbers);
Haskell:
squaredNumbers = map (\x -> x * x) numbers
sum = foldl (+) 0 numbers
Rust with Mathelogos:
let evens_squared = list_comprehension!(x * x, x <- &numbers, x % 2 == 0);
let mut lazy_value = Thunk::new(|| { add(5, 10) });
Haskell:
evensSquared = [x * x | x <- numbers, even x]
lazyValue = let value = add 5 10 in value
Rust with Mathelogos:
let result = Maybe::Just(5).map(|x| x * 2);
Haskell:
result = Just 5 >>= \x -> return (x * 2)
Mathelogos is licensed under Apache license version 2.0. See LICENSE file.