Dato il seguente, tratto da Typeclassopedia:Usando `apply` da` MyApplicative ((,) e) `
class MyApplicative f where
pure :: a -> f a
ap :: f (a -> b) -> f a -> f b
instance Monoid e => MyApplicative ((,) e) where
pure x = (mempty, x)
(u, f) `ap` (v, x) = (u `mappend` v, f x)
sto cercando di fare qualcosa di simile:
ghci> (+) <$> Control.Applicative.pure 100 <*> Control.Applicative.pure 50
150
ma, con la nuova definizione Applicative
:
ghci> Main.pure (+ 100) `ap` (Main.pure 50)
<interactive>:132:1:
No instance for (MyApplicative f0) arising from a use of `it'
The type variable `f0' is ambiguous
Note: there is a potential instance available:
instance Monoid e => MyApplicative ((,) e)
-- Defined at MonoidWork.hs:8:10
In the first argument of `print', namely `it'
In a stmt of an interactive GHCi command: print it
Guardando i tipi:
0.123.ghci> :t Main.pure (+ 100)
Main.pure (+ 100) :: (MyApplicative f, Num a) => f (a -> a)
e
ghci> :t (Main.pure 50)
(Main.pure 50) :: (MyApplicative f, Num a) => f a
Non capisco come risolvere l'errore di compilazione.