question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

infinite loop when evaluating a recursive given definition

See original GitHub issue

When running a program which consumes opaque types as follows, it appears to be stuck on an infinite loop. Not sure what is going on here.

Minimized code

object Prices {
  opaque type Price = BigDecimal

  object Price{
    given Ordering[Price] = summon[Ordering[BigDecimal]]
  }

}

extension[K,V] (m1: Map[K,V]) def computeDiff(m2: Map[K,V])(using Ordering[K])(using orderAsc: Boolean = true): Unit = println("Ok....")

import Prices._
@main def mainz = {
    println("begin")
    val result = Map.empty[Price,Int].computeDiff(Map.empty[Price,Int])
    println(s"end $result")
}

Scastie link: https://scastie.scala-lang.org/ajEagvzvTbitmzbqFt0Oxw

Output

begin

Expectation

Should successfully print the following:

begin
Ok....
end

This works if the Price was swapped with BigDecimal in the line

  val result = Map.empty[Price,Int].computeDiff(Map.empty[Price,Int])

This is happening on 3.0.0-M3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kubukozcommented, Feb 13, 2021

What’s interesting about this one is that one common use case is derivation (a la Haskell’s generalize newtype deriving). Would it be possible to hook something into the derivation mechanism?

@tel I really wish this was possible. I don’t see people switching from @newtype to opaque types anytime soon if this isn’t made easier - I just bumped on the issue at question myself and the boilerplate needed to do it “properly” is very discouraging.

2reactions
liufengyuncommented, Dec 29, 2020

We could enhance the initialization check to check for possible non-termination of lazy fields. A related issue #9668.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infinite loop - Wikipedia
Infinite recursion is a special case of an infinite loop that is caused by recursion. The following example in VBA returns a stack...
Read more >
what is the difference between while(1) infinite loop and a ...
A recursive function keeps calling itself whereas an infinite loop keeps repeating the same block of code. When a function ...
Read more >
Recursion and Looping | Baeldung on Computer Science
In simple terms, we can define looping or iteration as the process where the same set of instructions is repeated multiple times in...
Read more >
15-150 Lecture 3: Recursion; Structural Induction
I.e. it is an infinite loop. 1.2 Case case is a new operation on natural numbers. It lets you distinguish whether the number...
Read more >
If Statements, Loops and Recursion - OCaml
Now we come to a hard topic - recursion. Functional programmers are defined by their love of recursive functions, and in many ways...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found