Bounded polymorphism refers to existential quantifiers(∃), restricted to range over types of bound type. To understand it only needs a few examples. Let’s start! Take a look at the following program:
numSort::Numa=>[a]->[a]
Num a
is how we represent the bounded polymorphism inHaskell , the definition ofNum
wasclass Num b where
(Hoogle showsa
, just prevent to confuse reader don’t familiar withHaskell ) could read asa typeb
is an instance of classNum
.
SonumSort
takes[a]
only ifa
is an instance ofNum
. Now we could run down:
numSort[1,2,3]::[Int]numSort[1.1,2,3]::[Double]
This is really a powerful feature(and you don’t need to useHaskell for this,Java also has this feature), consider the old way to doList<A>
toList<B>
, and unfortunately solution was to copy each element in the list.
Top comments(1)

- Email
- LocationTaiwan
- EducationKaohsiung Medical University
- Joined
forgot that MathJax expression xd. Did anyone know how to use LaTeX in dev.to?
For further actions, you may consider blocking this person and/orreporting abuse