
Those operators are for Power Users - why put them in the Prelude? I mean, they are so money, I can't find words to describe them. Below are a few attempts. I start with a description in English, then implement using Functor's bling operators, and then again using the Prelude as-is. In each case, the code is shorter with the bling operators, but if you try to verbalize it, it's nonsense and the syntax is ungoogleable. import Data.Functor((<$>), (<$), ($>)) -- Map (+1) on a computation moneyCentric, moneyCentric2 :: IO Int moneyCentric = (+1) <$> return 1 moneyCentric2 = fmap (+1) $ return 1 -- Map (const 2) on a computation lessMoney, lessMoney2 :: IO Int lessMoney = 2 <$ return 1 lessMoney2 = fmap (const 2) $ return 1 -- Run a computation, but then return 2. moneyGreaterThan, moneyGreaterThan2 :: IO Int moneyGreaterThan = return 1 $> 2 moneyGreaterThan2 = return 1 `butReturn` 2 where m `butReturn` x = m >> return x And check this out: Prelude> 2 <$ return 1 <interactive>:2:3: Not in scope: ‘<$’ Perhaps you meant one of these: ‘<’ (imported from Prelude), ‘<=’ (imported from Prelude), ‘$’ (imported from Prelude) The syntax '<$' is close enough to '<=' and '$' that ghci guesses it was a typo. Shouldn't we assume this syntax would make a beginner's head spin? If you really want to use those operators, import Data.Functor. Why must it be in the Prelude? -Greg
Dne út 24. 2. 2015 16:39 uživatel Edward Kmett
napsal: We have a couple of weeks until the third release candidate for GHC 7.10 goes out the door.
Along the way with the last couple of release candidates folks have found some problems with the way we implemented the AMP. [1][2]
Most notably, we failed to include (<$>) in the Prelude, so the standard idiom of
foo <$> bar <*> baz <*> quux
doesn't work out of the box!
I'd like to include (<$>) in the Prelude in RC3.
I'd also like to invite discussion about whether folks believe we should include (<$) out of the box.
(<$) has been a member of Functor for a long time, which is only visible if you import it from Data.Functor or bring in Control.Applicative. There is an idiom that you use (<*) and (<$) to point to the parts of the structure that you want to keep the answers from when building longer such Applicative chains.
Discussion Period: 2 weeks
Thank you, -Edward Kmett
[1] http://www.reddit.com/r/haskell/comments/2wzixa/shouldnt_be_in_prelude/ [2] https://plus.google.com/115504368969270249241/posts/URzeDWd7qMp _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries