A monad is created by defining a type constructor M and two operations, bind and return (where return is often also called unit):

  • The unary return operation takes a value from a plain type (a) and puts it into a container using the constructor, creating a monadic value (with type M a).
  • The binary bind operation ">>=" takes as its arguments a monadic value with type M a and a function (a → M b) that can transform the value.
    • The bind operator unwraps the plain value with type a embedded in its input monadic value with type M a, and feeds it to the function.
    • The function then creates a new monadic value, with type M b, that can be fed to the next bind operators composed in the pipeline.

With these elements, the programmer composes a sequence of function calls (the "pipeline") with several bind operators chained together in an expression. Each function call transforms its input plain type value, and the bind operator handles the returned monadic value, which is fed into the next step in the sequence. Between each pair of composed function calls, the bind operator can inject into the monadic value some additional information that is not accessible within the function, and pass it along. It can also exert finer control of the flow of execution, for example by calling the function only under some conditions, or executing the function calls in a particular order.

https://en.wikipedia.org/wiki/Monad_(functional_programming)

Monad的基本运算的更多相关文章

  1. Functional Programming without Lambda - Part 2 Lifting, Functor, Monad

    Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...

  2. Sass的基本运算(转载)

    转载于:http://www.cnblogs.com/Medeor/p/4966952.html Sass中的基本运算 一.加法 在 CSS 中能做运算的,到目前为止仅有 calc() 函数可行.但在 ...

  3. Atitit 理解Monad attilax总结

    Atitit 理解Monad attilax总结 但函数式编程最大的一个问题是,函数是一个数学抽象,在现实世界中不存在,1 那既然这样就够用了,还要 Monad 干嘛?Monad 的作用在这里就体现出 ...

  4. Scalaz(41)- Free :IO Monad-Free特定版本的FP语法

    我们不断地重申FP强调代码无副作用,这样才能实现编程纯代码.像通过键盘显示器进行交流.读写文件.数据库等这些IO操作都会产生副作用.那么我们是不是为了实现纯代码而放弃IO操作呢?没有IO的程序就是一段 ...

  5. Scalaz(32)- Free :lift - Monad生产线

    在前面的讨论里我们提到自由数据结构就是产生某种类型的最简化结构,比如:free monoid, free monad, free category等等.我们也证明了List[A]是个free mono ...

  6. Scalaz(28)- ST Monad :FP方式适用变量

    函数式编程模式强调纯代码(pure code),主要实现方式是使用不可变数据结构,目的是函数组合(composability)最终实现函数组件的重复使用.但是,如果我们在一个函数p内部使用了可变量(m ...

  7. Scalaz(25)- Monad: Monad Transformer-叠加Monad效果

    中间插播了几篇scalaz数据类型,现在又要回到Monad专题.因为FP的特征就是Monad式编程(Monadic programming),所以必须充分理解认识Monad.熟练掌握Monad运用.曾 ...

  8. Scalaz(20)-Monad: Validation-Applicative版本的Either

    scalaz还提供了个type class叫Validation.乍看起来跟\/没什么分别.实际上这个Validation是在\/的基础上增加了Applicative功能,就是实现了ap函数.通过Ap ...

  9. Scalaz(19)- Monad: \/ - Monad 版本的 Either

    scala标准库提供了一个Either类型,它可以说是Option的升级版.与Option相同,Either也有两种状态:Left和Right,分别对应Option的None和Some,不同的是Lef ...

随机推荐

  1. node13---node使用mongodb

    01.js /** *最先的后台语言是Asp(微软的), */ var express = require("express"); //数据库引用 var MongoClient ...

  2. 安装Oracle RAC 11g

    1.Oracle Enterprise Linux 和 iSCSI 上构建 Oracle RAC 11g 集群 2.Oracle RAC 的所有共享磁盘存储将基于 iSCSI,iSCSI 使用在第三个 ...

  3. 极客时间 mysql实战45讲下载读 08讲事务到底是隔离的还是不隔离的 笔记

    笔记体会: 1.innodb支持RC和RR隔离级别实现是用的一致性视图(consistent read view) 2.事务在启动时会拍一个快照,这个快照是基于整个库的.基于整个库的意思就是说一个事务 ...

  4. 1.future线程通信

    #include <future> #include<iostream> #include <thread> #include <thread> #in ...

  5. Kettle的四大不同环境工具

    不多说,直接上干货! kettle里有不同工具,分别用于ETL的不同阶段. 初学者,建议送Spoon开始.高手,是四大工具都会用. Sqoop: 图形界面工具,快速设计和维护复杂的ETL工作流.集成开 ...

  6. hbase的命令

    1.1. 命令 名称 命令表达式 创建表 create '表名', '列族名1','列族名2','列族名N' 查看所有表 list 描述表 describe  ‘表名’ 判断表存在 exists  ' ...

  7. solarwinds之网络发现

    1.  首先需要添加网络发现   2.  使用public   3.  添加主机   4.  网络地址选择   5.  默认下一步   6.  运行发现   7.  扫描结构如下   8.  下一步 ...

  8. Unknown column 't_user.id' in 'where clause'(通过字段名删除不了数据)

    创建员工信息表t_user CREATE TABLE t_user( id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(20) , passwor ...

  9. python 之 MRO 异常

    今天突然遇到这个异常,先贴两个地址,待有时间写博客 https://www.jianshu.com/p/fea6e0a0cc14 https://makina-corpus.com/blog/meti ...

  10. input标签type为number时,输入小数,在Firefox浏览器上输入框标红的问题

    问题一:firefox 下 默认情况 <input   type="number"> 只允许输入整数,输入小数时会报错,输入框被标红 这时候可以添加参数 step=&q ...