fmap fmap如何应用于函数(作为参数)?

时间:2015-03-03 06:21:42

标签: function haskell types functor function-composition

我想了解fmap fmap如何应用于像(*3)这样的函数。

fmap fmap的类型:

(fmap fmap):: (Functor f1, Functor f) => f (a -> b) -> f (f1 a -> f1 b)

(*3)的类型:

(*3) :: Num a => a -> a

这意味着签名a -> a对应f (a -> b),对吗?

Prelude> :t (fmap fmap (*3))
(fmap fmap (*3)):: (Num (a -> b), Functor f) => (a -> b) -> f a -> f b

我尝试过创建一个简单的测试:

test :: (Functor f) => f (a -> b) -> Bool 
test f = True

(*3)喂入其中,但我得到了:

*Main> :t (test (*3))

<interactive>:1:8:
    No instance for (Num (a0 -> b0)) arising from a use of ‘*’
    In the first argument of ‘test’, namely ‘(* 3)’
    In the expression: (test (* 3))

为什么会这样?

0 个答案:

没有答案