[Haskell-beginners] Pattern Matching for record syntax

Magnus Therning magnus at therning.org
Thu Jan 7 22:51:59 UTC 2016


Jeon-Young Kang writes:

> For pattern matching.. I implemented like this.
>
> compareName a (Person name age)
>         | (a == name) = age
>
> but, I got stuck how to apply pattern matching for the two lists.
> i.e., both names and persons are lists.
>
> I really appreciate your advice..

Something like this works:

    map age $ filter (\ p -> (name p) `elem` names) persons

/M

--
Magnus Therning              OpenPGP: 0x927912051716CE39
email: magnus at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus

Finagle's Fifth Law:
Always draw your curves, then plot your readings.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160107/2b0fc6df/attachment.sig>


More information about the Beginners mailing list