- concat (map f x)
- map g (map f x)
- putStr . (++) "\n"
Often this is because the new user is unfamiliar with the existance of a particular function, of course they can Hoogle it, if they thought it might exist, but often it never occurs to them.
The solution is Haskell Suggest, have a tool that automatically spots and suggests these things. I think the best implementation would be using Yhc Core for a couple of reasons, its relatively unmodified (no advanced transformations like inlining), has source positions and is simple.
Sounds like a good idea to go and implement.... Credits to dons for discussing this on Haskell IRC.
So it would, for example, suggest these instead of the above?
ReplyDelete- x >>= f
- map (g . f) x
- putStrLn
That would be pretty cool.
It would for the last two, but it would suggest concatMap for the first example - the idea is to keep it matching the users original idea and thought process - so now the kind of @pl transformations of lambdabot.
ReplyDeleteI think you mean (putStr . (++ "\n")), not (putStr . (++) "\n").
ReplyDeleteIndeed, you are right. It just so happens that the code I was helping someone refactor did it that way - so obviously they were wrong before hand!
ReplyDeleteActually it would have to be putStr . (flip (++) "\n") for putStrLn.
ReplyDeleteIn Haskell (++ "\n") === (flip (++) "\n"), so either would do.
ReplyDelete