
On Fri, Feb 26, 2010 at 5:12 PM, Daniel Fischer
Am Freitag 26 Februar 2010 17:37:30 schrieb Magnus Therning:
It doesn't look like a complete piece of code so these comments aren't backed up by running it through GHCi or anything.
On Fri, Feb 26, 2010 at 16:29, Florian Duret
wrote: Hello,
I try to set up a verification on the number of arguments given to my program, but keep on getting "Parse error in pattern" Here is what my code looks like: main :: IO() main = do -- On commence par ouvrir le fichier SAC en mode binaire argsList <- getArgs if (length (argsList) == 0)
It's most likely harmless for argument lists (although there are other cases), but
Don't Use
if (length list == 0)
Never. Jamais. Niemals.
Use
if (null list)
length has to traverse the entire list, which may take a long time.
While the advice here is sound 90% of the time, it's evidence of falling into the trap of underestimating lazyness. If 0 and length list are both of type Nat, the first will be exactly as fast as the second. Bob