- 论坛徽章:
- 95
|
原帖由 sw2wolf 于 2009-6-15 12:58 发表 ![]()
谢谢! 但我不明白如下定义中, 能解释下吗?
(***) :: 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 编辑 ] |
|