-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Wuerker
committed
Jun 14, 2024
1 parent
680e3a9
commit 8bd77f2
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use self::option::Option | ||
|
||
trait Applicative | ||
where Self: * -> * | ||
{ | ||
fn pure<T>(t: T) -> Self<T> | ||
} | ||
|
||
impl Applicative for Option { | ||
fn pure<T>(t: T) -> Self<T> { | ||
Option::Some(t) | ||
} | ||
} | ||
|
||
trait Monad: Applicative | ||
where Self: * -> * | ||
{ | ||
fn bind<T, F, U>(t: Self<T>) -> Self<U> where F: Fn<T, Self<U>> | ||
} | ||
|
||
impl Monad for Option { | ||
fn bind<T, F, U>(t: Self<T>) -> Self<U> where F: Fn<T, Self<U>> { | ||
match t { | ||
Self::Some(t) => F::exec(t) | ||
Self::None => Self::None | ||
} | ||
} | ||
} | ||
|
||
trait Fn<T, U> { | ||
fn exec(t: T) -> U | ||
} | ||
|
||
type MyFn = () | ||
|
||
impl Fn<bool, Option<u8>> for MyFn { | ||
fn exec(t: bool) -> Option<u8> { | ||
Option::Some(0) | ||
} | ||
} | ||
|
||
#test | ||
fn my_test() { | ||
type OptionU8 = Option<u8> | ||
let a = OptionU8::bind<bool, MyFn, u8>(Option::Some(true)) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
enum Option<Inner> { | ||
pub enum Option<Inner> { | ||
Some(Inner), | ||
None | ||
} |