The Unreasonable Effectiveness of Constructive Data Modeling
Comments
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
So today I'm going to be talking about constructive data modeling. Um but first just a couple of words about me. My reputation does precede me. I think if there's any particular thing that I'm most wellknown for, you probably encountered this blog post. Um if I had known at the time that it was going to be as popular as it was, I might not have chosen to write all of the examples in HASLL. [laughter] But I was mostly writing it for my co-workers at the time. And and until just a couple years ago, I was actually um writing Haskell professionally. in fact working on the Haskell compiler professionally. Um, but that's no longer true. I decided that I got tired of that and now I write product software. I'm writing Scola at a company called August Health. We build software used by caregivers at senior living facilities, assisted living facilities. And in particular, I work on the medications team. And I'm not going to go into too much detail about it because it's very complicated. But I will just say that it is very important that software uh that our software works because if it doesn't then somebody might not get their meds and that is very very bad. So we care a lot about our software working and of course we use lots of different techniques for doing that including testing. Um but the one that I want to talk about today is static typing.
Static typing is something that has been near and dear to my heart for a long time. And when I started programming, I kind of feel like we were actually in something of a static typing dark age where the main languages, statically typed languages that people were likely to be familiar with were Java and C++. And Java is of course an infamously conservative language, very very um restrictive and very object-oriented. And so I think a lot of people at the time kind of had this impression that static typing and object-orientation were sort of fundamentally connected um with all the pros and cons that come with that. And C++ on the other hand is very complex but it's also not really about safety. Um it comes from kind of this different heritage where types are mostly used to determine what the size and representation of values are and calling conventions and things like that. So I think a lot of people in this era had this impression that static typing was this kind of old thing that we didn't need anymore. Didn't provide very much of value. And it's no surprise that when I started programming professionally a lot of people were very excited about dynamically type languages, JavaScript, Ruby. Um, but I'm happy to say that I think in the time since then, we've kind of gone through the static typing renaissance. And I think this is probably best exemplified by the languages Rust and TypeScript.
And Rust, of course, is a very, very strong focus on safety. But they also uh introduced, I think, a lot of programmers to a collection of type system features that were in other languages, but um not maybe languages that had seen much mainstream use. And that's really, really nice. And Typescript as well has a number of features that I think probably most programmers that have used TypeScript had not encountered before and maybe haven't encountered anywhere else. And so with these two things together, static typing became cool again. And so you would think that given that I like static typing so much, I would be very happy with the status quo. I would say ah everything's wonderful and now we can just write safe programs using the type system. But that's not really true. I actually find this situation pretty unpleasant. Um and the reason for that is that there's been such an extreme increase so rapidly in type system complexity that in my experience most programmers say working with Typescript don't actually understand the way the type system works. Um they essentially treat the type checker as a black box and this results in a lot of frustration and you'll sometimes hear people talking about fighting with the type checker.
Raise your hand if you ever find yourself fighting with the type checker. It's a decent number of people. Um, and so when you find yourself in that situation and you don't understand what the whole type system is, how it works, then you might think, well, maybe I need some fancy elaborate type system feature. And of course, there's an ever growing set of type system features. And so it's very easy to think, well, this is just the way it is. This is the way that type systems are. And you just need to, you know, play type Tetris um for hours at a time or maybe ask an AI to come up with some solution. And this is a little surprising because we went from, you know, Java, this very very conservative uh language to Typescript.
What exactly changed that made programmers suddenly willing to accept the burden of all of this complexity? And I think the answer is, well, they they didn't really. Um, TypeScript was originally intended to be just typed JavaScript. So, lots of people had existing JavaScript code bases and so they wanted to have types uh they wanted to add types to it. And the problem with doing this is that the type system necessarily had to be a lot more complicated because it had to support dynamically typed idioms like doing something like this branching on the result of a type of check. And as a result, the type system is much more complex. Like if a language was designed to be static statically typed from the ground up would usually have some kind of more fit for purpose feature. Um but
sort of the the idea is that well programmers already have a mental model of the dynamic semantics. And when I say dynamic semantics, what I mean is sort of what the program does at runtime, what things evaluate to. And the idea is that if the type checker does its job well, then you can just kind of think about, well, okay, in the body of this if, then X is a string. And so the type checker should somehow magically be able to figure out that that is the case. But of course, this doesn't always happen. And because the type system is complex and it's just trying to uh not you know be be invisible to the programmer then when it is visible often programmers don't really know what to do. And this makes me really sad because we've sort of had this again timeline where we've jumped from one end of the type system complexity spectrum to the other one where both of them are frustrating. Java frustrating because it's too limiting, TypeScript frustrating because it's too complex. People don't necessarily understand exactly what's going on. And this might lead you to believe that the next step here is that I'm going to say that there's some mythical in between sweet spot where all the problems go away. And I don't think that's entirely untrue, but that's not really what this talk is about. So, personally, I don't ever feel like if I need the f checker whoops, bumped in the mic. Um, I write statically typed code all the time, every day, and I feel very equipped to utilize it to capture any number of invariants that I come across. And in spite of this, I'm actually using substantially less sophisticated type system machinery than I think a lot of programmers are using on a daily basis.
Um, but the most amazing thing is that I think that this is possible to do in just about any language that people are currently using that supports static types. Maybe not literally all of them, but certainly a lot of them. So let's make that a little more precise. The main ingredients for the techniques that uh I'm going to be talking about in this talk require some form of product types. That is types where you can just kind of combine things together. So tupil, strus, records, any of those some form of some type. So things where you have different variants. So algebraic data types, rust calls those enums, typescript unions, sealed interfaces in Scola. And you need some ability to uh do exhaustive case analysis, pattern matching on those different variants of these types such that the compiler will tell you when there are some that are not covered. And that's it. If you have a language that supports all these things, then all it takes to reap all these benefits is a shift in perspective. So let's talk about what that shift in perspective [clears throat] is and let's start from the philosophical. What are types? I think a lot of people um when presented with this question come up with the answer that types are restrictions and this is a very natural way of thinking about things especially in a language like TypeScript. We sort of have this universe of all these values that exist in JavaScript and we can give a name to the whole universe. In Typescript they call that unknown and then we can draw little bubbles um and give sort of names to these subsets and some of the subsets can even have smaller subsets within them. And so the types basically rule out the things that we don't want. They restrict the set of all possible values.
And so this seems like a very obvious way to think about things in Typescript. But if you really think about it, other languages don't work this way. Like if we look at say a class definition or a record definition in Java. If you don't like Java, that's okay. I have some more syntaxes here. Um, and the point is that for all of these different constructs, we're not just defining a new type called points. we're actually introducing a new class of value at runtime which is this point structure, right? This point class. And so we we can actually extend the set of possible values. So we're not really just restricting down, we're not ruling out some negative space, we're actually kind of defining some new positive space.
We're building things up from nothing. And this is the first key idea of this talk. Um it's very useful in a lot of situations to think about the positive space rather than the negative space. So to give a really simple example, suppose that we want to define a natural number type. Um if we have a language that maybe doesn't have unsigned integers, we might naturally think, well, an int can be used to represent natural numbers. But if we only want to represent the, you know, the counting numbers, numbers greater than or equal to zero, then we might think, well, okay, we need to have some type system feature to restrict the set of potential values. But the problem is that this is really hard to implement in type systems. There are some languages that support things like this.
They're usually called something like refinement types. Um, but it makes type inference really complicated. It makes type checking uh fairly complicated. And so a lot of languages don't provide this and in general it's very very hard to do. Um, impossible to do. So instead, if we could just start from an unsigned integer type which only includes the numbers that we care about, then it's very easy to go from that to a signed integer type. Now, of course, you wouldn't actually do this because we used two's complement signed integers, but the point that I'm making here is just that it tends to be easier to add things than to subtract them. Uh, as long as we can just define the positive space that only includes the values that we want, then it's much easier to encode things into the type system. So, let's give a few more examples of that. So, suppose that you have some list type in your library. And suppose that you want to define a non-mpy list type. Again, if you're thinking about things in just kind of this types as restrictions way, you might say, well, I want to have a list, but I want to restrict it so that the length is greater than zero. But again, that's very hard to actually implement. So instead, let's try and think about what the positive space is.
We can say, well, a non-empt list always has one element and then it also has zero or more additional elements. So given that this is just a combination of two things, we can just represent that directly as a tupole between one element and then zero or more elements. So we don't need any complex type system features. We don't need some fancy uh way, you know, TypeScript has some fitfor-purpose feature for this. But it's not actually necessary. Even if you don't have something like that, then this works just fine. And if you say want to define a list with an even number of elements, we can do the same thing. We can say, well, in an even list, elements always come in pairs, right? Each time you add a new element, you actually have to add two elements.
So we can just represent this as a list of pairs. Now, some people look at this and they say, well, this is sort of cheating, isn't it? Like this is not actually a list with an even number of elements. it's just a list of pairs. If I were to call first on my even list here, then I wouldn't get the first element. I would actually get the first two elements. And that's true. And you could wrap this up in some interface that um you know redefineses all the list methods. But that would be a lot of work and maybe it's not always worthwhile. The point that I'm making here is just that in general, if you can decouple your representation from the interpretation of that data, then you get a lot of flexibility and you can model a lot of things that maybe you would think that you needed a more complex type system to support. So sometimes especially in a language like TypeScript that kind of doesn't have very many different types like usually you're just kind of using the same set of arrays objects for everything then people will think well okay I have this idea in my head of what my data is so it has to have that particular type but of course this is not really true really your data is just some sequence of zero or more elements and you could represent that as an array in many cases it might even be possible to represent it as a set or a bag um but similarly if you think about well my data is just a sequence of one or more elements then this representation is very natural and so it's very important to get away I think from this idea that there is some privileged correct ideal representation of your data and instead free your mind
and be willing to come up with some other representation so let me give a slightly more complex example so suppose that you have some user structure and uh
a user can have an email or a phone or both but at least one must be set and So if you're imagining well this is just like the structure of my user class maybe it comes from my database I have two columns and this is just generated then in this case it's hard to enforce this in the type system you might say well maybe I need some fancy dependent typing thing where I can say well the type of the phone number depends on the value of email and again it's very easy to get kind of lost down this kind of rabbit hole and start thinking well you know in order to restrict my data I just need fancier and fancier features but of course this is not really necessary if you're willing to just introduce some additional type, some enumeration that defines exactly which possible states there are. That's not too bad. Um, I
don't know why this sometimes happens where the text disappears. Um, don't worry about that. [laughter] Um, but in this particular case, we don't need that comment anymore. It's just enforced in the type system. And if this is a lot of boiler plate, then obviously you could introduce some abstraction to say I have one value, some other value, or both. Um, Haskell calls this type these, which I always felt like is not a very useful name. Scola calls it, Scola Cats calls it iOS or, but I actually often like just keeping things simple and having just some fitfor-purpose type. And that's because then if this type changes in the future and now all of a sudden we need to introduce some new field that says, well, maybe this is a system user uh, which doesn't have an email address or a phone number at all, then we would introduce some optionality here. And then again, we're back to the comment situation. But again, we can just instead update this type and say, well, there's some fourth case. Um, so in general, if you're willing to really think through this and just think about like how could I actually model this in such a way using these tools that I'm only going to include the values I want, it is possible to express a lot of different things. Sometimes though, it can actually be pretty tricky. So it's definitely not always obvious or always free. So for example, suppose that we have some time range type where it has a start time and an end time and we want to have some invariant that says that the start time is always less than or equal to the end time. So we don't have ever have negative time ranges. How could we in theory represent this without some fancy type system feature that lets us express these restrictions?
How could we represent this constructively where we're only defining the positive space? Anyone have any have any ideas? >> That's right. So we could instead introduce Oh, I've lost focus on my
slide somehow. That's not good.
There you go. We can have a start time and a duration offset. So it's not always like the most obvious mechanical transformation, but it is often possible to do. And that's not always true. Sometimes maybe it's not worth it. It's not possible and you can just introduce some abstract type, but in many cases it is. But of course, there's often many different representations to pick. So I think another question I sometimes get is how do I know which one I should choose? And from my point of view, this question can be answered by really considering like what is the type system actually for at least from a correctness point of view. Obviously there's lots of different uses for the type system.
Things like tooling, autocompletes, performance optimizations. Um but I find that when I ask this question, I actually get a lot of different answers. Uh sort of people who don't really like static typing very much answer things like, well, you know, it prevents you from adding one in a string. Um, and I mean that's true. Uh, you know, in some situations that's actually kind of useful, but I think if the type system were only doing that, it probably wouldn't be worth all the ceremony. Um, people that are really into static typing, they say, "Oh, you know, it's about formally proving my program correct." And let me tell you, if you were formally proving your program correct, you would know. Um, you are probably not doing that.
[laughter] In the object-oriented days, you often had people who liked to be taxonomous where they would go around in their product domain and find all these different nouns and they would come up with a class for each and every one of them. And don't get me wrong, domain modeling is a very useful skill, but to be honest, it can be done in a dynamically typed language. There's not really any need for static typing, although it can be helpful. Um, so I think the most common answer I get these days, especially from sort of TypeScript programmers, is well, the ideal is just to write the right type of my data, right? I I want to have the maximally precise specification and the more fancy the type system gets then the more precise I can make my types and that's good. Um but I'm actually not sure that it's good and in fact I think the answer that I give is really much simpler than this which is just that the type system keeps track of the different cases that you have to handle in your code. So let me give an example that illustrates this. So suppose that you have some user type enumeration where we just have standard users, admin users and system users. Then we have some producers somewhere in our code that are actually sort of using these different types.
We're creating users with these different uh types of privileges. And then somewhere later in the code, we have some authorization function. And the key point here is that these two things can be really far apart, right? There could be some complex twisty sequence of calls. Could even end up in a database and then be read back out of a database. Um these two things are not close together in the code. But if we were to still, you know, need some new type of user, maybe we add a new type of API user or something like that, then our type system, as long as it has the ability to support like ensuring that our um pattern matches are exhaustive, then it will tell us immediately uh when we add that usage that producer somewhere, it will tell us all the consumers that we have to update. So from that point of view, a type system is really this sort of obligation propagation machine where you are just each type definition sort of relates the
places where you produce values and the places you consume values. And it is those use sites specifically that inform what the oblica obligations ought to be and this is I think where a lot of people seem to get tripped up. So let me use a somewhat more realistic a somewhat more concrete example. Um at work recently we've been dealing with sort of uh counting of inventory of medications. So ensuring that say narcotic drugs are not being stolen from these communities. And so we keep track of an inventory log which here is just represented as a list of inventory log entries. And each one of those has some change. So you know received 20 pills, administered one. And so maybe we want to get the total number and so we're just going to sum them all up. Now, it turns out that in our particular implementation, we never actually have an empty list of inventory log entries. If we have any inventory log at all, we are going to have at least one entry. So, we could in theory make things more complicated and use a more precise type and say that this is actually a non-MP list. But the list type is used everywhere and it's really convenient. And so given that a sum in this case is just going to actually return zero in the situation where the list is empty, it's really no big deal and we can just um use the plain old standard list type. But in a different situation, suppose that we have some other function where we just want to get the most recent entry and we want to get from the most recent entry the most recent time stamp. Then in this case, if we were to use just an ordinary list, then we wouldn't really have any way to handle the case where the list is empty.
And in that case, maybe we would insert some panic that just raises an error and says, well, that should never happen because the invariant say that it should never happen. But the problem is that as soon as you do this, as soon as you introduce these kinds of error conditions, then that is something that your type system cannot guarantee will not happen. And so it could in theory happen in the future. So in this situation, maybe it's worth it to strengthen that type to an list. But the point is that's only useful here because we're actually using this operation that otherwise could fail. And there is no need to strengthen the types. There's no need to make them any more precise than they need to be except when you have these situations where otherwise there could be an error raised at runtime. So this is actually the third key idea which is generally pick the easiest representation, the simplest representation that allows ruling out these cases where things just shouldn't happen. Um another way of putting this is that it's useful to write total functions. This is something that in functional programming we think is very lovely and it's true that in functional programming languages more say standard library functions tend to be total. That is to say they return a value for each potential input. Um they don't just raise an exception. They don't just throw. Uh and following this principle allows you to get a lot more value out of your type system. Now one additional example that I kind of want to walk through here is option types. So um
option types are really great and even in Typescript you can kind of have option types. They don't really use option types in the traditional sense usually. But the point is that there's just some way in the type system of tracking optionality. And I think a question that I'm not sure very many people I know have a compelling answer to is which is more restrictive just some value t or option of t. What do you think? Show of hands. How many people think that it's t is more restrictive? How many people think that it's option T that's more restrictive? Much smaller number. And I mean this is kind of a trick question like in some sense certainly the set of potential values the positive space of option T is larger but really it depends on how we actually go about using these values. So for example suppose that we have some function and we're going to use this function to notify when some failure happens in the system. So this is going to take an option user and it's going to be very easy and convenient. And this is great because then when we're implementing some function where maybe we don't have a user on hand, maybe we have some unauthenticated endpoint, then we can just pass in none. And so this seems like we're being very generous and not particularly restrictive. But of course, um the problem is that then when we go to implement some the the function that actually notifies some user about the failure when the case is none, then we don't really know what to do. And I find that, you know, when I end up in this situation when programming, it reminds me a lot of this particular tweet, which I find very funny.
[laughter]
So maybe using optional types is not always less restrictive. Maybe it's actually more restrictive. So let's try again. Let's instead implement the functions in a different order. And let's start by implementing this notify about failure function. And because it's much easier, we're going to make it not optional. But of course, in this case, we've actually just pushed the problem to this other function where now all of a sudden we have to decide what we're going to do in this particular case where we don't have a user on hand. But there is one key difference between these two things which is actually quite useful, which is that we've actually moved the obligation of where to handle the failure from one place to the other.
So by changing the types we're able to decide and this is kind of the parse don't validate idea. By changing the types you can move where the different you know failure conditions actually end up happening. And that to me is really um such a big point of of modeling your types in a particular way. In some cases they might have a lot of different cases at the sort of input to your program because there's lots of different failure modes. But then once you've handled that fail those failure modes then you can narrow the set. So um just to recap what we've seen so far,
defining your data's positive space is very good rather than its negative space. Decoupling your data representation from its interpretation is very helpful. Using type definitions to encode the obligations necessary to write total functions allows you to um basically take advantage of the type system to prove those invariants rather than just uh have a low confidence guess. And then you can use you can change your types to push obligations around to the places best equipped to handle them. And this is a very simple concept but in my experience um I see a lot of people who say have read pars don't validate and they get very confused because they think well you know I need to have some email address type that then pins down the type of every email address every everywhere in my system. And I don't really understand why people um feel that that is necessary. Okay, I just represent email addresses as strings because there is not actually any situation where I would need to look at the structure of an email address. I'm just going to hand it off to my, you know, email service. So, the way that I think about it is I just want to make my types as simple as possible, but no simpler. Um, so one
final point that I want to mention here before I open things up to questions is
um I I I want to make it clear that I do not think that fancy type system features are bad. Nancy type system features provide an awful lot of convenience. For example, going back to the non-empt list example. TypeScript has this feature which I think they call like variatic tupal types um where you can do this sort of splat this spread operation. And this allows you to model a non-mpt list. And the thing that's really great about this is that I mean it's an array not a list in in Typescript but point is the same. This still allows you to just use all the methods on array and it's very easy and it's very convenient. This is not a bad thing. This is great. If you have access to a feature like this, by all means, take advantage of it. Just do not get caught up on it and start thinking, well, you know, this means that we absolutely need to use those things to model all kinds of invariants. And if your language doesn't have some fit for purpose feature for keeping track of something like this, then it's just impossible. And the type system needs to be improved. We need to have dependent types. That's not really true. And that's it. That's all I have to say.
>> [applause]
[applause] >> questions.
Thanks. Good talk. I have tried to use
something called the type state pattern in Rust. Have you heard of this? This is like >> Yes. >> Okay. when it keeps you from calling certain functions when the enum's in a certain value. Have you ever tried to make this ergonomic and ended up being awful? What are your thoughts on it? >> Yeah, that's a good question. I mean, I think the way that I feel is that there's lots of sort of benefits to using type systems that are or using type type systems to model particular things that really do just tend to be a matter of sort of usability ergonomics. for example, like sometimes people will like to introduce type wrappers for different types of IDs. Like maybe you have a user ID and a post ID or something and you don't want to confuse those or um another example that people sometimes give are like keeping things with different units distinct. And that definitely does I'm going to fall off the fall off the platform here. Um it definitely does help to avoid accidentally confusing those things, but it doesn't really add type safety. It just sort of adds a speed bump. Now a speed bump can be useful um but it can also be annoying, right? It really just kind of depends. So I think for those sorts of things like the the the examples that I'm trying to focus on here are that this is like a concrete case where it prevents you from writing oops I needed to have the value be in a particular form but there's some case that I don't want to handle. Um I find those much more sort of unambiguously useful but there are other cases where like if you make a particular mistake a lot maybe you want to introduce a speed bump. So it really kind of depends on your use case and what the team happens to be. Um it's up to you.
U what are your opinions on in O languages where you have interfaces for example mutability of collections so for example you might have a concrete dictionary type that's mutable but actually the function or the data type only requires like an readonly dictionary so I saw a lot of things about concrete arrays but what happens with OO languages that have
these capabilities for example F has some types product types how do you reconcile allow with these OO or interface based systems. >> Um I'm not sure I entirely understand the question. >> So when thinking about representation and interpretation, you can think of like interfaces a way of specifying the way they're interpreted. Yeah. >> So would you focus on specifying concrete types or specifying just the interfaces? >> Yeah, that's a good question. I mean I definitely think that like this particular school of data modeling is
this is you know involves concrete types and I think part of the advantage of using concrete types in this way where you're able to pattern match on things for example is that like you
let me maybe give an example of this. It's possible to uh let me jump back to here.
It's possible to have say a definition of the non-empt list where you instead use an abstract type and in the constructor you just verify that this property is true and then if it isn't
then you either return none or you throw or something like that and then you only expose methods that maintain that invariant. And in some cases that's super great and in some cases it's actually much easier to do than trying to model it in this sort of concrete way. Um because then you can just use some arbitrary property and arbitrary boolean properties are very powerful. The problem of course then is you now have this like surface area where you have to maintain the invariant. Now for something like this maybe that's really really easy but something that's really great about this is that it is impossible to break the invariant.
Right? there is no sort of blessed code that has to worry about it. So I think
the people often conflate these two things. Um but this is a stronger uh property. And the other thing is that it allows you to kind of directly benefit from it. Like you can just get the first element. It's just there. It's available to you. Whereas in the case of like you have some abstract type, maybe you can define a method that gives you that first value. But of course it's going to be just like getting the first value out of the list and throwing if the invarium invariant is ever violated. So it sort of is that is a technique that allows you to model things that doesn't necessarily rely on the language whereas this kind of integrates the invariance more deeply into the language. So I tend to prefer this um you know something that doesn't require me to worry about some blessed surface area. But I mean both are useful techniques.
Hello. Uh so you used an example of you know constructively representing a time range as like a start with a duration rather than a start and an end time. Um a kind of maybe obvious objection to this is oh well now every time I need to know what the end time is I need to do a computation. Um but the benefit is that like I can make sure that you know this invariant is enforced by the representation here is the like when we think about like in runtime if like we need the end time a lot like should we be expecting language runtimes to I don't know privately memoize end time for us should we be doing this ourselves how do we kind of reconcile this maybe more constructive representation with the >> performance trade-offs >> that's a good question and I think actually like one of the things that is
interesting about this particular example is that it's not entirely consistent with what I was saying here which is that you know modeling this particular constraint constructively doesn't necessarily reduce the number of cases that you have to handle in the code there's not necessarily a situation where you would have to write like given the top representation here without that um you know restriction invariant you wouldn't necessarily have to throw um situations in which this has come up when I've been working on code is seeing well okay maybe I actually want to get the duration and I care that that duration is positive. So in that case, it would be very nice to have this bottom representation because the duration just happens to be on hand. But if I didn't care about that, if I really only care about the start and end times and I'm confident that, you know, like the duration doesn't really matter where I'm constructing those values, I will have already um ensured that it meets the appropriate invariance, then maybe I would want to use the one on the top. So again, it's just kind of u I think it is useful to use the representation that for the specific code that you are writing happens to be the most useful.
It's not really about trying to like capture every invariance about your data in the types. It's it's just the ones that allow you to avoid writing panic.
>> I was just going to ask about your opinion on dependently typed languages uh like address. Do you think that's the way forward or is it more more complication than we need or what do you think? >> I think I know enough to say I do not know. Um I have used dynamically typed languages. Haskell supports some limited forms of dynamic typing. Um TypeScript even supports some limited forms of dynamic typing or not dynamic typing dependent typing sorry. Um and I think that they are useful in some situations. in some situations maybe not worth it. I think the there's always it's always going to be a matter of opinion how much something like that is worthwhile especially because different domains require different degrees of confidence like I work on a codebase where we do care a lot about code working like the cost of failure is relatively high in some other domains it's even higher and so I think as with sort of all engineering trade-offs like that you can kind of dial it in depending on what you happen to be doing um I think When it comes to things like dependent types, one of the big challenges is code reuse.
As you as your types get more and more precise, then it becomes harder and harder to reuse things because you need a specific fitforpurpose model for each thing that makes it easy in your specific use case. So, because so much of engineering kind of depends on the network effects of library supports and things like that, um I'm not sure if it will ever sort of take take off in the mainstream, but maybe it will. I don't know. I don't think I know how software engineering is going to evolve. >> Excuse me. Oh, okay. H So, thank you for the talk, but uh I think I did not quite
understand the uh structure where you said h that a non empty list is either a t or a and then a
list of t. Uh my question with with this is that given that in most languages there is a specific uh interface that
list is required to implement how are
you going to be uh certain that the non-empt list will also be a list and will also be accepted in the same places because maybe it's not very clear in the
uh list example but in the non- empty list example But there are other cases where all subtypes must uh implement the
same interface no mat despite their structure uh being different. >> Yeah. I mean I think like I think the question is you know in in the case where you have a non-empt list then
um like would you have to implement the list interface and would that cause trouble like would you be able to implement the list interface in this particular case because it And I mean if the answer is no, then of course it doesn't implement the list interface. It's not a list like in in that sense. Um if there's you know the if you if you want to be able to implement a list where one of the methods is like remove all the elements then of course like it would not be a list in in that sense. So it really just kind of depends on what the interface is. But of course like if an a the list interface in your language of choice just allows you to like get particular elements out of the list then you could implement that. Um, >> obviously whether or not that's worthwhile again is is a is a judgment call that you have to make. Um, I certainly don't think that rigorously applying this in every single situation is necessary. There's absolutely cases in our codebase where we have a a just like this should never happen um throw.
But but it's a trade-off. >> So it's again it's a trade-off between whether reimplementing the the list interface for this particular type is maybe worth it or not. >> Right.





