[Haskell-beginners] Guards as extensions of patterns

Russ Abbott russ.abbott at gmail.com
Wed Sep 29 23:17:31 EDT 2010


I never realized that a guard can be used as an extension of a pattern.  Is
this recommended coding? elem n xs asks whether n is an element of xs

elem :: (Eq a) => a -> [a] -> Bool

elem _ [] 		       = False
elem n (x:_) | n == x = True
elem n (_:xs)            = elem n xs


-- Russ Abbott
______________________________________
  Professor, Computer Science
  California State University, Los Angeles

  Google voice: 424-242-USA0 (last character is zero)
  blog: http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
______________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100929/897464c2/attachment.html


More information about the Beginners mailing list