在haskell,我试过这个:
multi::(Num n)=>n->((a->a)->(a->a))
(multi 0) f x=x
(multi n) f x=(multi n-1) f (f x)
希望获得一个可以多次重复另一个功能的功能。在 ghci 我得到了这个:
[1 of 1] Compiling Main ( pad.hs, interpreted )
pad.hs:2:8:
Could not deduce (Eq n) arising from the literal `0'
from the context (Num n)
bound by the type signature for
multi :: Num n => n -> (a -> a) -> a -> a
at pad.hs:1:8-35
Possible fix:
add (Eq n) to the context of
the type signature for multi :: Num n => n -> (a -> a) -> a -> a
In the pattern: 0
In an equation for `multi': multi 0 f x = x
pad.hs:3:23:
Could not deduce (Num ((a -> a) -> a -> a))
arising from a use of `-'
from the context (Num n)
bound by the type signature for
multi :: Num n => n -> (a -> a) -> a -> a
at pad.hs:1:8-35
Possible fix:
add an instance declaration for (Num ((a -> a) -> a -> a))
In the expression: multi n - 1
In the expression: (multi n - 1) f (f x)
In an equation for `multi': multi n f x = (multi n - 1) f (f x)
Failed, modules loaded: none.
我是haskell的新手。我该怎么办?