3 ms·
I can see it working in a statically types language with macros - maybe Scala or Template Haskell? I'm not 100% sure if their metaprogramming is capable of this
by rpeden 10y ago
I can see it working in a statically types language with macros - maybe Scala or Template Haskell? I'm not 100% sure if their metaprogramming is capable of this. Ideally, you could define a type like FileNameString to be a string that has to match a certain regex. Though if you wanted to use the new type throughout your program, I suppose you'd need a String -> FileNameString function somewhere to handle instance of file names generated at runtime.
I agree that the type systems in most mainstream languages fall somewhere short of awesome. I was putting together a small web app in Elm last week, and it was nice to work with a type system that felt like it was helping me design and write better code. That, plus it has the most helpful errors message I've ever seen from a compiler.
- Too 10y agoActually it's quite common. For example in .net you have a Uri class and a DirectoryInfo class which are basically just wrappers on top of strings with some validation and helper functions.