-
Notifications
You must be signed in to change notification settings - Fork 192
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 18, 2024
1 parent
680e3a9
commit f4baa26
Showing
3 changed files
with
46 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,45 @@ | ||
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>(self: Self<T>) -> Self<U> where F: Fn<T, Self<U>> | ||
} | ||
|
||
impl Monad for Option { | ||
fn bind<T, F, U>(self: Self<T>) -> Self<U> where F: Fn<T, Self<U>> { | ||
match self { | ||
Self::Some(self) => F::exec(t: self) | ||
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() { | ||
let a = Option::Some(true).bind<bool, MyFn, u8>() | ||
} |
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 | ||
} |