mcfilib / ribimaybe Goto Github PK
View Code? Open in Web Editor NEWMaybe Functor, Applicative and Monad
License: MIT License
Maybe Functor, Applicative and Monad
License: MIT License
It's unfortunate that return
is a reserved keyword in Ruby and I worry that the ergonomics of #rturn
are unsatisfactory.
sorry for the terminology, I'm not familiar with the Contracts
library
Just(1).bind{|x|
Nothing.bind{|y|
rturn(x+y)}}
should return Nothing
. Instead:
Contract violation for return value: (ContractError)
Expected: Ribimaybe::Maybe::Just,
Actual: Ribimaybe::Maybe::Nothing
Value guarded in: Ribimaybe::Maybe::Just::bind
With Contract: Proc => Ribimaybe::Maybe::Just
pure id <*> v = v -- Identity
pure (.) <*> u <*> v <*> w = u <*> (v <*> w) -- Composition
pure f <*> pure x = pure (f x) -- Homomorphism
u <*> pure y = pure ($ y) <*> u -- Interchange
And the Functor instance should satisfy the following law:
fmap f x = pure f <*> x -- Fmap
[~]
% ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin13.0.0]
[~]
% irb
irb(main):001:0> require 'ribimaybe'
=> true
irb(main):002:0> include Ribimaybe::Maybe
=> Object
irb(main):003:0> Maybe(nil)
=> Ribimaybe::Maybe::Nothing
irb(main):004:0> puts Maybe(nil)
Nothing
=> nil
irb(main):005:0>
After receiving #22 I decided it would be nice if we could alias these methods to short binary operators, e.g. >>
, >=
.
m >>= return = m -- right unit
return x >>= f = f x -- left unit
(m >>= f) >>= g = m >>= (\x -> f x >>= g) -- associativity
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.