Applicative: The Forgotten Functional Pattern
1APPLICATIVE APPLICATIVE THE FORGOTTEN FUNCTIONAL PATTERN THE FORGOTTEN FUNCTIONAL PATTERN BEN DEANE / CPPCON / 2023-10-04 BEN DEANE / CPPCON / 2023-10-04 2DISCLAIMERS DISCLAIMERS No AI was used in on My Own Account, and Don't Like It Refresher (or introduction) for functor and monad Where applicative �ts 5FIRST, A QUICK SURVEY FIRST, A QUICK SURVEY 6FIRST, A QUICK SURVEY FIRST, A QUICK SURVEY written code that uses them, and it was good I completely understand a) functors b) monads c) applicative 6.5FIRST, A QUICK SURVEY FIRST, A QUICK SURVEY I've heard of these functional patterns, but that's0 码力 | 141 页 | 11.33 MB | 5 月前3The Idris Tutorial Version 0.9.18
Integer Having defined Functor, we can define Applicative which abstracts the notion of function application: infixl 2 <*> class Functor f => Applicative (f : Type -> Type) where pure : a -> f a (<*>) of do-notation introduced in Section “do” 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) more general, and applies to anything which is an instance of both Monad and Alternative: class Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a In general, a0 码力 | 69 页 | 316.20 KB | 1 年前3The Idris Tutorial Version 0.11
Integer Having defined Functor, we can define Applicative which abstracts the notion of function application: infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure : a -> f a (<*>) do-notation introduced in Section “do” notation. It extends Applicative as defined above, and is defined as follows: interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) and applies to anything which has an implementation of both Monad and Alternative: interface Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a In general, a0 码力 | 71 页 | 314.20 KB | 1 年前3The Idris Tutorial Version 0.9.20.1
Integer Having defined Functor, we can define Applicative which abstracts the notion of function application: infixl 2 <*> class Functor f => Applicative (f : Type -> Type) where pure : a -> f a (<*>) of do-notation introduced in Section “do” 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) more general, and applies to anything which is an instance of both Monad and Alternative: class Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a In general, a0 码力 | 71 页 | 316.18 KB | 1 年前3The Idris Tutorial Version 1.3.3
Functor, w e c an d e fi n e Applicative w h i c h ab s t r ac t s t h e n ot i on of f u n c t i on ap p l i c at i on : infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure ” n o t a t i o n ( p age 14) . I t e x t e n d s 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 -> i n g w h i c h h as an i m p l e m e n t at i on of b ot h Monad an d Alternative: interface Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a I n ge n e r0 码力 | 66 页 | 627.66 KB | 1 年前3The Idris Tutorial Version 1.3.4
Functor, w e c an d e fi n e Applicative w h i c h ab s t r ac t s t h e n ot i on of f u n c t i on ap p l i c at i on : infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure ” n o t a t i o n ( p age 14) . I t e x t e n d s 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 -> i n g w h i c h h as an i m p l e m e n t at i on of b ot h Monad an d Alternative: interface Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a I n ge n e r0 码力 | 66 页 | 627.66 KB | 1 年前3Idris 语言文档 Version 1.3.1
12, 14, 16, 18, 20] : List Integer 定义了 Functor 之后,我们就能定义应用子 Applicative 了, 它对函数应用的概念进行了抽象: infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure : a -> f a (<*>) : f (a -> b) 法 单子接口 Monad 允许我们对绑定和计算进行封装,它也是 「d o 」记法 夨 姩 妡妵 失夲天 一节中 do夭 记法的基础。 单子扩展了前面定义的 Applicative,其定义如下: interface Applicative m => Monad (m : Type -> Type) where (>>=) : m a -> (a -> m b) -> m b 在 do 块中会应用以下语法变换: 式 式 我们之间在 更多表达式 夨 姩 妡妵 失夹天 一节中看到的列表推导记法其实更通用, 它可应用于任何实现了 Monad 和 Alternative 的东西: interface Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a 通常,推导式形式为 [ exp0 码力 | 224 页 | 2.06 MB | 1 年前3The Idris Tutorial Version 0.99
Functor, w e c an d e fi n e Applicative w h i c h ab s t r ac t s t h e n ot i on of f u n c t i on ap p l i c at i on : infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure ” n o t a t i o n ( p age 12) . I t e x t e n d s 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 -> i n g w h i c h h as an i m p l e m e n t at i on of b ot h Monad an d Alternative: interface Applicative f => Alternative (f : Type -> Type) where empty : f a (<|>) : f a -> f a -> f a I n ge n e r0 码力 | 182 页 | 1.04 MB | 1 年前3The Idris Tutorial Version 1.0.1
8, 10, 12, 14, 16, 18, 20] : List Integer Hav i n g d e fi n e d Functor, w e c an d e fi n e Applicative w h i c h ab s t r ac t s t h e n ot i on of f u n c t i on ap p l i c at i on : 24 C H A P T T E R 1. T H E I D R I S T U T O R I A L v1. 0 infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b M on ad s an d do- n ot at ” n o t a t i o n ( p age 13) . I t e x t e n d s 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 ->0 码力 | 223 页 | 1.21 MB | 1 年前3The Idris Tutorial Version 1.1.0
8, 10, 12, 14, 16, 18, 20] : List Integer Hav i n g d e fi n e d Functor, w e c an d e fi n e Applicative w h i c h ab s t r ac t s t h e n ot i on of f u n c t i on ap p l i c at i on : 24 C H A P T T E R 1. T H E I D R I S T U T O R I A L v1. 0 infixl 2 <*> interface Functor f => Applicative (f : Type -> Type) where pure : a -> f a (<*>) : f (a -> b) -> f a -> f b M on ad s an d do- n ot at ” n o t a t i o n ( p age 13) . I t e x t e n d s 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 ->0 码力 | 223 页 | 1.21 MB | 1 年前3
共 52 条
- 1
- 2
- 3
- 4
- 5
- 6