3 ms·
Oh interesting; is that actually true? I'm not aware of Haskell features that allow it to do better than any of the three other languages I compared to in my po
by sestep 1y ago
Oh interesting; is that actually true? I'm not aware of Haskell features that allow it to do better than any of the three other languages I compared to in my post. What would my running example look like in Haskell?
- instig007 1y agoHere's the sample you can play with (interactive: https://play.haskell.org/saved/TWBEYFzH https://play.haskell.org/saved/TWBEYFzH): {-# LANGUAGE RecordWildCards #-} main = transport ("2025-09-05T09:00:00Z", "2025-09-05T11:00:00Z") foo123 kwargs where foo123 = Foo kwargs = Kwargs {..} bar = Bar person = Person {..} name = "Alex Smith" phone = "+1 (555) 555-5555" options = Opts {..} fragile = True window = PM data Foo = Foo data Bar = Bar data Kwargs = Kwargs { bar :: Bar , person :: Person , options :: Opts } data Person = Person { name :: String , phone :: String } data Opts = Opts { fragile :: Bool , window :: HalfDay } data HalfDay = AM | PM transport (start, end) foo Kwargs { person = Person{ name = who, ..}, options = Opts{..}, ..} = do doStuff who foo moreStuff phone end window otherThings start fragile bar doStuff who foo = print "called doStuff" moreStuff phone end window = print "called moreStuff" otherThings start fragile bar = print "calle otherThings"
- instig007 1y agoTo address the example towards the end of your post, if you want patterns + struct binding at the same time, prefix patterns with `bindName@`, for instance: transport myTuple@(start, end) foo kwargs@(Kwargs { person = Person{ name = who, ..}, options = Opts{..}, ..}) = do ...
- sestep 1y agoI see, so similar to the other languages I mentioned in my post, it looks like Haskell doesn't let you colocate the types with the leaves of the binding form?
- instig007 1y ago> doesn't let you colocate the types with the leaves of the binding form Can you elaborate on the effective difference between colocations in your example and this: transport Kwargs {person = Person{name = who, ..}, options = Opts{..}, ..} The `Kwargs{..}` alone does imply a non-ambiguous type in the function signature (without explicit but optional annotations), and it binds locally scoped names too. Why doesn't it colocate in the same sense?
- sestep 1y agoIt's similar to the Rust example from my post: there are no anonymous records, so in order to be able to construct something with named fields, you need to first define those record types outside. In contrast, my proposed syntax depends on already having anonymous record types like OCaml and TypeScript do, but avoids the extra boilerplate required by separating types from binding forms as shown in my TypeScript example.
- instig007 1y agoBut structural typing that allows you defining anonymous record types is orthogonal to colocation of types and bindings. You're effectively saying that you're proposing a type system that supports structural types, syntax and colocation don't have much to do with it.
- sestep 1y agoCould you clarify what you mean? TypeScript already has structural types, but I already examined it in my post; if that were the only thing I was saying then my post would have just used TypeScript at the top.