klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

Polymorphism #22

Open klequis opened 2 years ago

klequis commented 2 years ago

From Haskell First Principles

  1. Polymorphism refers to type variables that may refer to more than one concrete type. In Haskell, this will usually manifest as parametric or ad-hoc polymorphism. By having a larger set of types, we intersect their commonalities to produce a smaller set of correct terms. This makes it less likely that we’ll write an incorrect program and lets us reuse the code with other types.

  2. Polymorphism means being able to write code in terms of values that may be one of several types or of any type. There are two types in Haskell and, as I understand them currently

    • Parametric is unconstrained such as id :: a -> a
    • Constrained is constrained as isEqual :: Eq a => a -> a -> Bool.

Issues

  1. 2 is likely only partially correct. 'Constrained' maybe a subset of 'ad-hock'.

  2. There are fuller definitions of terms found here and they should be added.