diff --git a/library/core/src/monad.fe b/library/core/src/monad.fe index e69de29bb..3881b9606 100644 --- a/library/core/src/monad.fe +++ b/library/core/src/monad.fe @@ -0,0 +1,46 @@ +use self::option::Option + +trait Applicative +where Self: * -> * +{ + fn pure(t: T) -> Self +} + +impl Applicative for Option { + fn pure(t: T) -> Self { + Option::Some(t) + } +} + +trait Monad: Applicative +where Self: * -> * +{ + fn bind(t: Self) -> Self where F: Fn> +} + +impl Monad for Option { + fn bind(t: Self) -> Self where F: Fn> { + match t { + Self::Some(t) => F::exec(t) + Self::None => Self::None + } + } +} + +trait Fn { + fn exec(t: T) -> U +} + +type MyFn = () + +impl Fn> for MyFn { + fn exec(t: bool) -> Option { + Option::Some(0) + } +} + +#test +fn my_test() { + type OptionU8 = Option + let a = OptionU8::bind(Option::Some(true)) +} \ No newline at end of file diff --git a/library/core/src/monad/map.fe b/library/core/src/monad/map.fe new file mode 100644 index 000000000..e69de29bb diff --git a/library/core/src/monad/option.fe b/library/core/src/monad/option.fe index 418b6de81..6e8bfa479 100644 --- a/library/core/src/monad/option.fe +++ b/library/core/src/monad/option.fe @@ -1,4 +1,4 @@ -enum Option { +pub enum Option { Some(Inner), None } \ No newline at end of file