pub trait HasTruth fn isTruthy() -> Boolean def fn isFalsy() -> Boolean = !self.truthy end pub trait Functor[Self] fn map(f: fn (t: T) -> U) -> Self end pub trait Lift[Self] static fn lift(t: T) -> Self end pub trait Applicative[Self, U, V] : Functor[Self] + Lift[Self] where T is fn (u: U) -> V fn apply(us: Self) -> Self end pub trait Monad[Self] : Functor[Self] + Lift[Self] fn flatMap(f: fn (t: T) -> Self) -> Self end // Traits as higher-kinded types // - Cannot be used as concrete types, casted, etc. // - Cannot be constructed/instantiated // - Imports are different: // ``` // use std::core::Option // use std::trait::Monad[Option<*>] // bring in Monad for all Option<*> // ``` // - Once imported, fns are in scope // - Can also be looked-up 'dictionary' style: // ``` // use std::trait::HasTruth[Option] // // fn main() // let maybeTruthy: Option = someOtherApiCall() // if HasTruth[maybeTruthy].isTruthy() then // println "It's truthy." // end // ```