On Thu, Jun 10, 2010 at 2:10 PM, Maciej Piechotka <uzytkown...@gmail.com> wrote: > data Named a = Named String a > > instance Functor Named where > f `fmap` (Named s v) = Named s (f v) > > instance Applicative Named where > pure x = Named "" x > (Named s f) <*> (Named t v) = Named (s ++ "(" ++ t ++ ")") (f v)
This is not technically a legal applicative instance, because it is not associative. This can be seen when you try to clean up the usage as we have been discussing: g <.> f = liftA2 (.) g f f = Named "f" (+1) g = Named "g" (*2) h = Named "h" (^3) ghci> f <*> (g <*> (h <*> namedPure 42)) f(g(h(42))) ghci> (f <.> g <.> h) <*> namedPure 42 f(g)(h)(42) The Applicative laws are supposed to guarantee that this refactor is legal. Of course, the latter answer is nonsense. Luke _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe