Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

林子篆
林子篆

Posted on • Originally published atdannypsnl.github.io on

     

NOTE: bounded polymorphism

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]
Enter fullscreen modeExit fullscreen mode

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]
Enter fullscreen modeExit fullscreen mode

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
dannypsnl profile image
林子篆
I am a programming language theory lover; good at system software like Networking, OS.
  • Email
  • Location
    Taiwan
  • Education
    Kaohsiung Medical University
  • Joined

forgot that MathJax expression xd. Did anyone know how to use LaTeX in dev.to?

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a programming language theory lover; good at system software like Networking, OS.
  • Location
    Taiwan
  • Education
    Kaohsiung Medical University
  • Joined

More from林子篆

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp