[Haskell-beginners] Guards as extensions of patterns

Brandon S Allbery KF8NH allbery at ece.cmu.edu
Thu Sep 30 00:21:54 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 9/29/10 23:17 , Russ Abbott wrote:
> 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

Yep (although perhaps not ideal in this particular case).  Moreover, the
same things work in case statements (which function definition by patterns
desugar to); IIRC "if c then t else e" is internally converted to "case ()
of () | c -> t | _ -> e".

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkykEGIACgkQIn7hlCsL25WeaACguJXxy2EqO0suNG0KxRVBC2aP
aAEAmwXt6sBk9Unb/hbNxPzP16v6NtFS
=sVav
-----END PGP SIGNATURE-----


More information about the Beginners mailing list