Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Do Scala's match types implement full dependent types?

Parent

Do Scala's match types implement full dependent types?

+2
−0

Do Scala's match types support full spectrum dependent types, and if not, what capabilities do they lack?

History

0 comment threads

Post
+2
−0

Dependent types are types that depend on values. Scala's match types enable expressing types that depend on types. Scala's other type system features include path-dependent types, which allow types to depend on paths that represent values, but outside of literals and singletons, there is no way to express values themselves in the type system. So no, these are not full dependent types.

As an example of what isn't possible:

type MyTuple[n, A] = n match
  case 0 => Unit
  case 1 => A
  case 2 => (A, A)

def myfn(n: Int): MyTuple[n, String] = n match
  case 0 => ()
  case 1 => ""
  case 2 => ("", "")

Changing MyTuple[n, String] to MyTuple[n.type, String] doesn't help. n.type is a path-dependent type, so the type system knows that all occurrences of n.type are the same, but it doesn't know the run-time value of n and so can't reduce MyTuple enough to check the three cases.

History

1 comment thread

Confused by term-like type literals (7 comments)
Confused by term-like type literals
deleted user wrote 7 months ago · edited 7 months ago

Ah, I think what's been confusing me is that in the paper they use numeric literals at the type level, but they're singleton types for numeric terms. So it looks like they're matching on terms at the type level, but they're not.

System‭ wrote 7 months ago

Thread renamed from "Ah, I think what's been confusing me is that in the paper they use numeric literals at the type level..." to "Confused by term-like type literals" by deleted user

Skipping 1 deleted comment.

deleted user wrote 7 months ago

OK I think this is because n in MyTuple is necessarily a singleton type, whereas in myfn it's both an Int and a singleton type, which doesn't work as is, but the only way to make it work would be to make it a singleton type everywhere, at which point n is no longer a term, but a type, which is clearly not dependent.

deleted user wrote 7 months ago

Nope, I still don't get how this is different from the paper example def random_normal[S <: Shape](shape: S): NDArray[Float, S] = ???

r~~‭ wrote 7 months ago

I don't know what paper you're referencing, but in general, S doesn't contain all of the information in the value shape. A type that depends on S can therefore only use the information in the S variable, and not the information in the shape variable. A dependently-typed language could use both.

deleted user wrote 7 months ago · edited 7 months ago

Type-level programming with match types, the original match types paper. I bring up this example because if their random_normal is implementable, I imagine sth effectively the same as myfn is too (with singletons), though I didn't figure out how to implement it

r~~‭ wrote 7 months ago

NDArray appears to be defined as a trait, not as a match type, so I don't think the two examples are analogous. There are lots of ways to potentially define that trait and implement it in random_normal, and the ones that come to my mind don't require any of the recent advances in Scala 3. How easy or difficult a trait is to instantiate depends entirely on the signatures of its members, and we aren't given that.

You'll notice that later in the paper, when match types come into play, there are examples of type-level arithmetic being performed on the Int singletons encoded in Shape. The fact that these are compiler-provided operators distinct from their value-level counterparts is another demonstration that this isn't a fully dependently-typed language. In Agda, for example, after defining a multiplication operator on terms, the operator is also usable in types. Dependently-typed languages largely collapse the distinction between terms and types as separate categories of thing.