Good Haskell Style

Seth Kurtzberg seth at cql.com
Wed Aug 1 11:33:06 EDT 2007


I've been using Haskell daily for a long time, and I didn't know about that
underscore convention.  I knew about _ being an unspecified dummy variable,
but I didn't know you are allowed to follow it with a meaningful name.

Guess I have some reading to do.  :)

-----Original Message-----
From: libraries-bounces at haskell.org [mailto:libraries-bounces at haskell.org]
On Behalf Of Chris Kuklewicz
Sent: Wednesday, August 01, 2007 11:31 AM
To: Philippa Cowderoy
Cc: libraries at haskell.org; Simon Marlow
Subject: Re: Good Haskell Style

Philippa Cowderoy wrote:
> On Wed, 1 Aug 2007, Simon Marlow wrote:
> 
>> I'm rather attached to the convention I use, which is
>>
>>   - CamelCase for exported identifiers
>>   - underscores otherwise
> <snip>
>> Yes I'm aware that a single-word identifier is the same in both
conventions;
>> it's not perfect.
>>
> 
> How about _nonexportedIdentifier or something similar?
> 

Leading underscores are used in pattern matches to indicate to GHC that
unused
names like '_foo' should not cause a warning to be printed.  Otherwise the
warning is turned off by using just '_'  but that erases the readability of
using an actual name.

Thus:

take _  [] = []  -- no warning
take n  [] = []  -- warning that n is unused
take _n [] = []  -- no warning

_______________________________________________
Libraries mailing list
Libraries at haskell.org
http://www.haskell.org/mailman/listinfo/libraries




More information about the Libraries mailing list