Skip to content

compiletime ops could interpret non-literal arguments under algebraic laws #9792

Open
@weihsiu

Description

@weihsiu

i did switch matching on 'that' instead of 'this' per @smarter 's suggestion but to no avail. operations that keeps the same list length like map and zip were ok but concat is giving me problems.

Minimized code

enum NList[N <: Int, +A]:
  def concat[M <: Int](that: NList[M, A]): NList[N + M, A] = this match
    case NNil => that
    case NCons(h, t) => NCons(h, t.concat(that))
  case NNil extends NList[0, Nothing]
  case NCons(head: A, tail: NList[N, A]) extends NList[N + 1, A]

Compiler Output

[error] -- [E007] Type Mismatch Error: 
[error] 10 |      case NNil => that
[error]    |                   ^^^^
[error]    |               Found:    (that : tlp.NLists.NList[M, A])
[error]    |               Required: tlp.NLists.NList[N + M, A]
[error]    |
[error]    |               where:    M is a type in method concat with bounds <: Int
[error] -- [E007] Type Mismatch Error:
[error] 11 |      case NCons(h, t) => NCons(h, t.concat(that))
[error]    |                                            ^^^^
[error]    |              Found:    (that : tlp.NLists.NList[M, A])
[error]    |              Required: tlp.NLists.NList[M², A$1]
[error]    |
[error]    |              where:    M  is a type in method concat with bounds <: Int
[error]    |                        M² is a type variable with constraint <: Int

Expectation

Compiles successfully

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions