- 論壇徽章:
- 95
|
原帖由 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 編輯 ] |
|