Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Last active May 3, 2018 12:52
Show Gist options
  • Save ethagnawl/744e01a832cd77de9a83da9047a8e18d to your computer and use it in GitHub Desktop.
Save ethagnawl/744e01a832cd77de9a83da9047a8e18d to your computer and use it in GitHub Desktop.
ad hoc vs. parametric polymorphism
-- The key difference between parametric polymorphism and overloading (aka ad-hoc
-- polymorphism) is that parameteric polymorphic functions use one algorithm to
-- operate on arguments of many different types, whereas overloaded functions may
-- use a different algorithm for each type of argument.
-- John Mitchell, Concepts in Programming Languages
-- http://stackoverflow.com/a/13043262/382982
-- ad hoc/constrained => typeclasses
plus :: (Num a) => a -> a -> a
plus a b = (+) a b
-- parametric => generics
swap :: (A, B) -> (B, A)
swap (a, b) = (b, a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment