The Idris Tutorial Version 0.9.18-> Type) where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b 4.4 Monads and do-notation The Monad class allows us to encapsulate binding and computation, and is the basis of do-notation introduced notation. It extends Applicative as defined above, and is defined as follows: class Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b Inside a do block, the following syntactic becomes let x = v in e IO is an instance of Monad, defined using primitive functions. We can also define an instance for Maybe, as follows: instance Monad Maybe where Nothing >>= k = Nothing (Just x)0 码力 | 69 页 | 316.20 KB | 1 年前3
 The Idris Tutorial Version 0.11-> Type) where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b 4.4 Monads and do-notation The Monad interface allows us to encapsulate binding and computation, and is the basis of do-notation introduced It extends Applicative as defined above, and is defined as follows: interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b Inside a do block, the following syntactic becomes let x = v in e IO has an implementation of Monad, defined using primitive functions. We can also define an implementation for Maybe, as follows: Monad Maybe where Nothing >>= k = Nothing (Just x)0 码力 | 71 页 | 314.20 KB | 1 年前3
 The Idris Tutorial Version 0.9.20.1-> Type) where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b 4.4 Monads and do-notation The Monad class allows us to encapsulate binding and computation, and is the basis of do-notation introduced notation. It extends Applicative as defined above, and is defined as follows: class Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b Inside a do block, the following syntactic becomes let x = v in e IO is an instance of Monad, defined using primitive functions. We can also define an instance for Maybe, as follows: instance Monad Maybe where Nothing >>= k = Nothing (Just x)0 码力 | 71 页 | 316.18 KB | 1 年前3
 Idris 语言文档 Version 1.3.14 单 单 单子 子 子与 与 与 do- 记 记 记法 法 法 单子接口 Monad 允许我们对绑定和计算进行封装,它也是 「d o 」记法 夨 姩 妡妵 失夲天 一节中 do夭 记法的基础。 单子扩展了前面定义的 Applicative,其定义如下: interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (\x => e) • v; e 变为 v >>= (\_ => e) • let x = v; e 变为 let x = v in e IO 实现了 Monad,它使用原语函数定义。我们也可以为 Maybe 定义实现, 其实现如下: Monad Maybe where Nothing >>= k = Nothing (Just x) >>= k = k x 通过它,我们可以定义一个将两个 版 版本 本 本 1. 3. 1 单 单 单子 子 子推 推 推导 导 导式 式 式 我们之间在 更多表达式 夨 姩 妡妵 失夹天 一节中看到的列表推导记法其实更通用, 它可应用于任何实现了 Monad 和 Alternative 的东西: interface Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>)0 码力 | 224 页 | 2.06 MB | 1 年前3
 The Idris Tutorial Version 0.99P T E R 1. T H E I D R I S T U T O R I A L v0. 99 1. 4. 4 M on ad s an d do- n ot at i on T h e Monad i n t e r f ac e al l ow s u s t o e n c ap s u l at e b i n d i n g an d c om p u t at i on , an Applicative as d e fi n e d ab ov e , an d i s d e fi n e d as f ol l ow s : interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b I n s i d e a do b l oc k , t h e f ol e m e n t at i on of Monad, d e fi n e d u s i n g p r i m i t i v e f u n c t i on s . W e c an al s o d e fi n e an i m p l e m e n - t at i on f or Maybe, as f ol l ow s : Monad Maybe where Nothing0 码力 | 182 页 | 1.04 MB | 1 年前3
 The Idris Tutorial Version 1.0.1where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b M on ad s an d do- n ot at i on T h e Monad i n t e r f ac e al l ow s u s t o e n c ap s u l at e b i n d i n g an d c om p u t at i on , an Applicative as d e fi n e d ab ov e , an d i s d e fi n e d as f ol l ow s : interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b I n s i d e a do b l oc k , t h e f ol e m e n t at i on of Monad, d e fi n e d u s i n g p r i m i t i v e f u n c t i on s . W e c an al s o d e fi n e an i m p l e m e n - t at i on f or Maybe, as f ol l ow s : Monad Maybe where Nothing0 码力 | 223 页 | 1.21 MB | 1 年前3
 The Idris Tutorial Version 1.1.0where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b M on ad s an d do- n ot at i on T h e Monad i n t e r f ac e al l ow s u s t o e n c ap s u l at e b i n d i n g an d c om p u t at i on , an Applicative as d e fi n e d ab ov e , an d i s d e fi n e d as f ol l ow s : interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b I n s i d e a do b l oc k , t h e f ol e m e n t at i on of Monad, d e fi n e d u s i n g p r i m i t i v e f u n c t i on s . W e c an al s o d e fi n e an i m p l e m e n - t at i on f or Maybe, as f ol l ow s : Monad Maybe where Nothing0 码力 | 223 页 | 1.21 MB | 1 年前3
 The Idris Tutorial Version 0.99.2where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b M on ad s an d do- n ot at i on T h e Monad i n t e r f ac e al l ow s u s t o e n c ap s u l at e b i n d i n g an d c om p u t at i on , an Applicative as d e fi n e d ab ov e , an d i s d e fi n e d as f ol l ow s : interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b I n s i d e a do b l oc k , t h e f ol e m e n t at i on of Monad, d e fi n e d u s i n g p r i m i t i v e f u n c t i on s . W e c an al s o d e fi n e an i m p l e m e n - t at i on f or Maybe, as f ol l ow s : Monad Maybe where Nothing0 码力 | 224 页 | 1.22 MB | 1 年前3
 The Idris Tutorial Version 1.1.1where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b M on ad s an d do- n ot at i on T h e Monad i n t e r f ac e al l ow s u s t o e n c ap s u l at e b i n d i n g an d c om p u t at i on , an Applicative as d e fi n e d ab ov e , an d i s d e fi n e d as f ol l ow s : interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b I n s i d e a do b l oc k , t h e f ol e m e n t at i on of Monad, d e fi n e d u s i n g p r i m i t i v e f u n c t i on s . W e c an al s o d e fi n e an i m p l e m e n - t at i on f or Maybe, as f ol l ow s : Monad Maybe where Nothing0 码力 | 223 页 | 1.21 MB | 1 年前3
 The Idris Tutorial Version 1.3.1pure : a -> f a (<*>) : f (a -> b) -> f a -> f b 1. 4. 4 M on ad s an d do- n ot at i on T h e Monad i n t e r f ac e al l ow s u s t o e n c ap s u l at e b i n d i n g an d c om p u t at i on , an Applicative as d e fi n e d ab ov e , an d i s d e fi n e d as f ol l ow s : interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b I n s i d e a do b l oc k , t h e f ol e m e n t at i on of Monad, d e fi n e d u s i n g p r i m i t i v e f u n c t i on s . W e c an al s o d e fi n e an i m p l e m e n - t at i on f or Maybe, as f ol l ow s : Monad Maybe where Nothing0 码力 | 230 页 | 1.24 MB | 1 年前3
共 15 条
- 1
 - 2
 













