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

Duane Johnson duane.johnson at gmail.com
Thu Apr 2 20:36:29 EDT 2009


Perhaps it wouldn't be as all-wonderful as I think, but as a "new"  
Haskell user, I am constantly switching back and forth between various  
definitions of things trying to compare documentation and files...

The purpose of "expansion" as I was explaining it is not to  
*permanently replace* what is in the text, but rather to *temporarily  
replace* it.  I imagine it kind of like a "zoom in" for code.  You  
could "zoom in" on one function, and seeing a new function that you  
don't recognize, "zoom in" again, and so on.  Once done, you would hit  
"ESC" to make it all return as it was.

BTW, I do like your suggestion of tooltip types.  That would be very  
handy!

Duane Johnson

On Apr 2, 2009, at 6:24 PM, Zachary Turner wrote:

> 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 cake.
>
> 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/6abdaa2b/attachment.htm


More information about the Haskell-Cafe mailing list