[Haskell-cafe] use of modules to save typing

Michael Mossey mpm at alumni.caltech.edu
Thu Jul 8 06:35:49 EDT 2010



Neil Brown wrote:
> 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? 

Generally I prefer static abbreviations rather than dynamic expansion or 
auto-completion, because static abbreviations have predictable behavior.

I'm a bit obsessive-compulsive, so I get annoyed when, say, 
pl<expand-key> expands to something shorter than I expected. With static 
abbreviations, behavior is 100% predictable. The abbreviations I choose, 
like "xps" follow a convention so they are easy to remember. They have 
no capitals.

Plus the identifier before and after the period can be more generic and 
reusable, and in that case dynamic expansion is more reliable, or I'm 
more likely to benefit from defining a static abbreviation.

> With that set of definitions, typing 
> pl<expand-key> should give you playState_ (it expands to the longest 
> unambigious expansion),

Hmm, when I use dabbrev-expand it expands to a complete identifier, but 
you can keep invoking it to rotate through all compatible identifiers. 
Maybe you are describing a mode I wasn't aware of.

I do use dabbrev-expand extensively, but once an identifier becomes very 
common I make a static abbreviation.

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

For example, as soon as I define playState_crunch then the behavior of 
dabbrev-expand changes. That's my complaint.

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

Interesting, so you have abandoned it for indentation... but I guess 
typing spaces works okay. Or do you do something else?

  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.

It does work quite well. One of the most successful "dumb algorithms" I 
know.

Thanks,
Mike



More information about the Haskell-Cafe mailing list