- 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.
6 comments:
So it would, for example, suggest these instead of the above?
- 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.
I think you mean (putStr . (++ "\n")), not (putStr . (++) "\n").
Indeed, 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!
Actually it would have to be putStr . (flip (++) "\n") for putStrLn.
In Haskell (++ "\n") === (flip (++) "\n"), so either would do.
Post a Comment