Thursday, June 29, 2006

Haskell Suggest

Often a more experienced Haskell user can point out some clever trick in some Haskell code that a beginner may not know about, for example:

  • 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:

Anonymous said...

So it would, for example, suggest these instead of the above?
- x >>= f
- map (g . f) x
- putStrLn
That would be pretty cool.

Neil Mitchell said...

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.

Anonymous said...

I think you mean (putStr . (++ "\n")), not (putStr . (++) "\n").

Neil Mitchell said...

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!

Anonymous said...

Actually it would have to be putStr . (flip (++) "\n") for putStrLn.

Neil Mitchell said...

In Haskell (++ "\n") === (flip (++) "\n"), so either would do.