kurumishka / optional

Haskell Either monad in C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

optional

Haskell Either monad implementation in C++. Just for fun.

Interface

General monadic interface have two main methods:

class Monad m where
    return    :: a -> m a                  -- (1)
    (>>=) m k :: m a -> (a -> m b) -> m b  -- (2)

(1) is a pure function in optional.cpp; (2) is an <<= operator overloaded. Binder is right to left, so it's equal to an =<< operator in Haskell.

When calling a constructor of Optional<L, R> class, default null left value should be passed also. Also can initialised with pure:

auto value = pure(std::string("ok"), 10) // :: Optional<std::string, int>

License

MIT

About

Haskell Either monad in C++.

License:MIT License


Languages

Language:C++ 100.0%