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:

  1. Anonymous3:59 PM

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

    ReplyDelete
  2. 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.

    ReplyDelete
  3. Anonymous4:41 PM

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

    ReplyDelete
  4. 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!

    ReplyDelete
  5. Anonymous6:54 AM

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

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

    ReplyDelete