亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: "***"怎么理解? [打印本頁]

作者: sw2wolf    時間: 2009-06-15 08:50
標題: "***"怎么理解?
import Control.Arrow ((***))

splitVerticallyBy,splitHorizontallyBy :: RealFrac r => r -> Rectangle -> (Rectangle, Rectangle)
splitVerticallyBy f = (mirrorRect *** mirrorRect) . splitHorizontallyBy f . mirrorRect

mirrorRect :: Rectangle -> Rectangle
mirrorRect (Rectangle rx ry rw rh) = (Rectangle ry rx rh rw)

Prelude> :m Control.Arrow
Prelude Control.Arrow> :i ***
class (Control.Category.Category a) => Arrow a where
  ...
  (***) :: a b c -> a b' c' -> a (b, b') (c, c')
  ...
          -- Defined in Control.Arrow
infixr 3 ***

不明白(mirrorRect *** mirrorRect) . splitHorizontallyBy f . mirrorRect 中, "***"的用法!
作者: MMMIX    時間: 2009-06-15 10:23
原帖由 sw2wolf 于 2009-6-15 08:50 發(fā)表
splitVerticallyBy,splitHorizontallyBy :: RealFrac r => r -> Rectangle -> (Rectangle, Rectangle)
splitVerticallyBy f = (mirrorRect *** mirrorRect) . splitHorizontallyBy f . mirrorRect

這里用的是 (->) 的 Arrow instance,因此有
mirrorRect *** mirrorRect :: (Rectangle, Rectangle) -> (Rectangle, Rectangle)
(mirrorRect *** mirrorRect) (r1, r2) = (mirrorRect r1, mirrorRect r2)

詳見 Control.Arror 源碼中的 instance Arrow (->)。
作者: sw2wolf    時間: 2009-06-15 12:58
標題: 回復 #2 MMMIX 的帖子
謝謝!  但我不明白如下定義中, 能解釋下嗎?

(***) :: a b c -> a b' c' -> a (b, b') (c, c')
作者: flw    時間: 2009-06-15 13:41
*** 的意思是說,把一個復合流中的兩個子流進行分流,然后分別應用到兩個箭頭上去,其結(jié)果仍然是一個復合流。
作者: MMMIX    時間: 2009-06-15 14:48
原帖由 sw2wolf 于 2009-6-15 12:58 發(fā)表
謝謝!  但我不明白如下定義中, 能解釋下嗎?

(***) :: a b c -> a b' c' -> a (b, b') (c, c')

看不懂 (***) 的類型?對比看看下面兩個:

class Arrow a where
    ...
    (***) :: a b c -> a b' c' -> a (b, b') (c, c')
    ...


instance Arrow (->) where
    ...

對于 instance Arrow (->), (***) 類型中的 a 就是 (->), 這是一個 type constructor, 則有
(***) :: (b -> c) -> (b' -> c') -> ((b, b') -> (c, c'))

再對比 (***) 的應用,(mirrorRect *** mirrorRect), 其中

mirrorRect :: Rectangle -> Rectangle

也可寫成

mirrorRect :: (->) Rectangle Rectangle

也即這里應該選用 (->) 的 Arrow instance,有

a = (->)
b, c, b', c' = Rectangle

那么
mirrorRect *** mirrorRect :: (Rectangle, Rectangle) -> (Rectangle, Rectangle)

這下知道如何利用 type inference 來理解 (***) 的類型了吧?

[ 本帖最后由 MMMIX 于 2009-6-15 14:50 編輯 ]
作者: sw2wolf    時間: 2009-06-15 18:34
原帖由 MMMIX 于 2009-6-15 14:48 發(fā)表

看不懂 (***) 的類型?對比看看下面兩個:

class Arrow a where
    ...
    (***) :: a b c -> a b' c' -> a (b, b') (c, c')
    ...


instance Arrow (->) where
    ...

對于 instance Arr ...

比較清楚了,謝謝!




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2