Здравствуйте, я пытаюсь сделать следующее:
module MyMonad where
f::(Monad m),=>m (a->b->c)->m a -> m b -> m c
f mf ma mb=
ma >>= \a ->
mb >>= \b ->
mf >>= \c ->
return (c a b)
и использовать его так:
f (Just 3) (Just 4)
И я получаю следующую ошибку:
* Non type-variable argument in the constraint: Num (a -> b -> c)
(Use FlexibleContexts to permit this)
* When checking the inferred type
it :: forall a b c.
(Num a, Num (a -> b -> c)) =>
Maybe b -> Maybe c
Я не знал, как поместить несколько ограничений типа, поэтому я попытался так:
f (Just [3]) (Just [4]) (++)
- (зная, что (++)
может быть применен к любому типу - будучи monoid
).
В этом случае я получаю следующее исключение:
* Couldn't match expected type `Maybe b0'
with actual type `[a1] -> [a1] -> [a1]'
* Probable cause: `(++)' is applied to too few arguments
In the third argument of `f', namely `(++)'
In the expression: f (Just [3]) (Left [3]) (++)
In an equation for `it': it = f (Just [3]) (Left [3]) (++)