仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述Haskell语言学习笔记(60)Biapplicative相关的知识,希望能为你提供帮助。
Biapplicative
class Bifunctor p =>
Biapplicative p where
bipure :: a ->
b ->
p a b(<
<
*>
>
) :: p (a ->
b) (c ->
d) ->
p a c ->
p b d(*>
>
) :: p a b ->
p c d ->
p c d
a *>
>
b = bimap (const id) (const id) <
<
$>
>
a <
<
*>
>
b(<
<
*) :: p a b ->
p c d ->
p a b
a <
<
* b = bimap const const <
<
$>
>
a <
<
*>
>
b(<
<
$>
>
) :: (a ->
b) ->
a ->
b
(<
<
$>
>
) = id
【Haskell语言学习笔记(60)Biapplicative】Biapplicative 是个类型类。主要用于在二元数据结构上应用 Applicative。
(,) 是个 Biapplicative
instance Biapplicative (,) where
bipure = (,)
(f, g) <
<
*>
>
(a, b) = (f a, g b)
Const 是个 Biapplicative
instance Biapplicative Const where
bipure a _ = Const a
Const f <
<
*>
>
Const x = Const (f x)
应用 Biapplicative
Prelude Data.Biapplicative>
((+2),(*3)) <
<
*>
>
(3,4)
(5,12)
Prelude Data.Biapplicative Control.Applicative>
Const (+2) <
<
*>
>
Const 3
Const 5
Prelude Data.Biapplicative>
bimap (+) (*) <
<
$>
>
(2,3) <
<
*>
>
(3,4)
(5,12)
Prelude Data.Biapplicative Control.Applicative>
bimap (+) (*) <
<
$>
>
Const 2 <
<
*>
>
Const 3
Const 5
(< < **> > ), biliftA2, biliftA3
(<
<
**>
>
) :: Biapplicative p =>
p a c ->
p (a ->
b) (c ->
d) ->
p b d
(<
<
**>
>
) = biliftA2 (flip id) (flip id)biliftA2 :: Biapplicative w =>
(a ->
b ->
c) ->
(d ->
e ->
f) ->
w a d ->
w b e ->
w c f
biliftA2 f g a b = bimap f g <
<
$>
>
a <
<
*>
>
bbiliftA3 :: Biapplicative w =>
(a ->
b ->
c ->
d) ->
(e ->
f ->
g ->
h) ->
w a e ->
w b f ->
w c g ->
w d h
biliftA3 f g a b c = bimap f g <
<
$>
>
a <
<
*>
>
b <
<
*>
>
c
Prelude Data.Biapplicative>
(2,3) <
<
**>
>
((2^), (3*))
(4,9)
Prelude Data.Biapplicative>
biliftA2 (+) (*) (2,3) (4,5)
(6,15)
Prelude Data.Biapplicative Control.Applicative>
biliftA2 (+) (*) (Const 2) (Const 3)
Const 5
推荐阅读
- Android 第三方库RxLifecycle使用
- win8系统提示“内存不足,请保存文件并关闭这些程序”怎样办
- win8系统服务管理如何添加mysql?win8系统服务管理添加mysql的办法
- 最新w8.1系统下载|下载最好用的w8.1系统
- 未激活的Win8系统能运用多久时间?是否影响系统运行?
- win8系统如何增加虚拟内存|win8系统增加虚拟内存的办法
- win8.1系统禁用或增加开机打开项的办法
- W8旗舰版系统下载 下载安全可靠的W8旗舰版系统
- win8系统打开telnet远程管理工具组件的办法【图文】