---
title: "Discussion on \"F-bounded polymorphism in Scala\" | Hashnode"
description: "Discussion on \"F-bounded polymorphism in Scala\". Polymorphism in programming languages is a powerful concept. F-bounded polymorphism is nothing other than a specific form of polymorphism."
url: "https://hashnode.com/posts/f-bounded-polymorphism-in-scala/6569948474c19a72dd3cf0d5"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [F-bounded polymorphism in Scala](https://brieuckaisin.hashnode.dev/f-bounded-polymorphism-in-scala?utm_source=hashnode&utm_medium=feed)

Polymorphism in programming languages is a powerful concept. F-bounded polymorphism is nothing other than a specific form of polymorphism.

Dec 1, 2023 · 13 min read · brieuckaisin.hashnode.dev  
Updated Dec 3, 2023  
Read the article

-   [#quantification](https://hashnode.com/tag/quantification)
-   [#scala](https://hashnode.com/tag/scala)
-   [#types](https://hashnode.com/tag/types)
-   [#polymorphism](https://hashnode.com/tag/polymorphism)
-   [#object-oriented-programming](https://hashnode.com/tag/object-oriented-programming)

## Written by

[Brieuc Kaisin](https://hashnode.com/@BrieucKaisin)

@BrieucKaisin · Belgium

  
[View profile](https://hashnode.com/@BrieucKaisin)

Functional programming enthusiast, passionate Scala lover

## Responses 1

Markdown supported · ⌘↵ to post

[Stulemeijer Thierry](https://hashnode.com/@ThierryS)

[Mar 25, 2024](https://hashnode.com/posts/f-bounded-polymorphism-in-scala/6569948474c19a72dd3cf0d5/comment/6601324ee8a285b9bdd90833)

Hi Brieuc, congrats for this nice article! As discussed in [contributors.scala-lang.org/t/is-f-bound-polymorp…](https://contributors.scala-lang.org/t/is-f-bound-polymorphism-useful/3618,) F-bounded polymorphism should most of the time be replaced by a simple minded Typeclass. In your case, this would give the following code (Scala 3 syntax):

trait Info\[T, InfoType\]: extension (infoType: InfoType) def update(t: T): InfoType

trait Memory\[T\]

case class Foo(foo: String) case class Bar(foo: Foo, foos: List\[Foo\])

case class FooInfo(fooMemory: Memory\[String\]): def update(foo: Foo): FooInfo = ??? object FooInfo: given Info\[Foo, FooInfo\] with extension (fooInfo: FooInfo) def update(foo: Foo): FooInfo = fooInfo.update(foo)

case class BarInfo( fooInfo: FooInfo, foosInfo: ListInfo\[Foo, FooInfo\] ): def update(bar: Bar): BarInfo = ???

object BarInfo: given Info\[Bar, BarInfo\] with extension (barInfo: BarInfo) def update(bar: Bar): BarInfo = barInfo.update(bar)

case class ListInfo\[T, InfoType\]( infos: List\[InfoType\] )(using Info\[T, InfoType\]): def update(listInfo: List\[T\]): ListInfo\[T, InfoType\] = ??? def updateInfoAtIndex(index: Int, t: T): ListInfo\[T, InfoType\] = val updatedInfo = infos(index).update(t) copy(infos = infos.updated(index, updatedInfo))
