[Haskell-cafe] use of modules to save typing

Neil Brown nccb2 at kent.ac.uk
Thu Jul 8 06:11:13 EDT 2010

On 08/07/10 09:08, Michael Mossey wrote:
> data PlayState = PlayState
>                  { playState_cursor :: Int
>                  , playState_verts :: [Loc]
>                  , playState_len :: Int
>                  , playState_doc :: MusDoc
>                  }
> Notice how often the characters "playState_" get typed. This would be 
> a great situation for Emacs abbreviations. When you define an 
> abbreviation in Emacs, such as defining "xps" to expand to 
> "PlayState", emacs will watch for the characters xps. It will then 
> replace "xps" with "PlayState" when you type a non-alphanumeric 
> character following "xps". So if I type "xps." the moment I hit "." it 
> changes to "PlayState."
> But I would have a hard time using this feature with "playState_" 
> because it is always followed by an alphanumeric character.
What about auto-completion?  With that set of definitions, typing 
pl<expand-key> should give you playState_ (it expands to the longest 
unambigious expansion), and adding c<expand-key> should give you 
playState_cursor.  So you get the full thing for about five keystrokes, 
without any worrying about alphanumeric vs non-alphanumeric.

I have completion bound to tab in emacs (a la tab completion in the 
shell): "(global-set-key (kbd "TAB") 'dabbrev-expand)" and am pretty 
happy with this for Haskell coding.  dabbrev-expand does not perform any 
Haskell-specific context-sensitive completion -- it just picks words out 
of open buffers, but I've found this to work to my satisfaction.  One 
additional nice thing is that after a completed word, if you press space 
then <expand-key> again, it inserts the most common next word after your 
previous completion based on open buffers.  Since in Haskell function 
calls and types are separated by spaces, this allows you to quickly 
complete common "phrases" from your Haskell code.



More information about the Haskell-Cafe mailing list