[Haskell-cafe] Wishful thinking: a text editor that expands function applications into function definitions

Zachary Turner divisortheory at gmail.com
Thu Apr 2 20:24:42 EDT 2009

It seems like a neat feature, and it could just be my inexperience with
Haskell but it doesn't seem "killer".  For example, why would you want to
expand readLine like that if you already have it defined?  It seems to
defeat much of the benefit of functional languages in the first place, which
is that it's so easy to reuse code by composing functions into new
functions.  I can see the case where you're passing all constants to a
function, because then supposedly inlining it might be more efficient, but I
would think the compiler would optimize most of the cases for you anyway.

One feature that I -do- think would be killer though, is the ability for the
editor to do a mouse-over tooltip of a) function definitions, and b)
arbitrary expressions.  So like in your example above, hovering the mouse
over `minus` in the expression p1 `minus` p2 would pop up a two line tooltip
that looked like this

minus :: (Num a, Num b, Num c) => (a,b,c) -> (a,b,c) -> (a,b,c)
minus :: first -> second -> (a,b,c)

Something along those lines.  It's nice to be able to see names of function
arguments without having to navigate away from the line you're editing.
This isn't the killer yet though since it's actually pretty standard for
most sufficiently advanced programming language IDEs.  The killer is that
the mouse-over event would also look one line above the function definition
for a comment.  It would then scan backward until it finds no more
comments.  It would then display that text above the function definition.
It's great having a type signature, but comments would just be icing on the

For arbitrary expressions, suppose you had the following function:

replaceItem :: [a] -> (a -> Bool) -> a -> [a]
let replaceItem xs pred = (: filter (not.pred) xs)

You then highlight the text "filter (not.pred)" and hover over the
highlighted text.  The mouse then pops up a tooltip that says "[a] -> [a]".
That would be killer IMO

On Thu, Apr 2, 2009 at 7:01 PM, Duane Johnson <duane.johnson at gmail.com>wrote:

> So I was thinking about a "killer feature" for a text editor.  Wouldn't it
> be neat if you could expand function calls into their definitions, in-place?
> For example, suppose we have "minus" defined like so, somewhere in another
> file:
>  minus (a, b, c) (x, y, z) = (a - x, b - y, c - z)
> Later, we make use of the function in our current context:
>  let p1 = (1, 2, 3)
>>     p2 = (4, 5, 6)
>> in p1 `minus` p2
> By telling the editor to "expand" the minus, we get a temporary replacing
> of the above with:
>  (1 - 4, 2 - 5, 3 - 6)
> Another example:
>   parse s = map readLine ls
> And supposing that readLine is defined somewhere else, moving the cursor to
> readLine in the line above and "expanding" becomes:
>   parse s = map (\line -> words $ dropWhile (== ' ') line)
> This is all pretty standard for the kinds of things we do in Haskell to
> work it out by hand, but is there any reason the parser couldn't do this?  I
> think it would be even harder to do automatically in any other language.
>  Maybe it's already been attempted or done?
> Curious,
> Duane Johnson
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090402/a0ee9de5/attachment.htm

More information about the Haskell-Cafe mailing list