[Haskell-beginners] Parse error in pattern
Tom Davie
tom.davie at gmail.com
Sat Feb 27 09:41:29 EST 2010
On Fri, Feb 26, 2010 at 5:12 PM, Daniel Fischer <daniel.is.fischer at web.de>wrote:
> 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 <flo.morphe at gmail.com>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100227/e3ecf912/attachment.html
More information about the Beginners
mailing list