6 ms·
>so tired of having to hunt down what functions are going to return, sometimes having to resort to just using it With highly generic functions, it's often not
by logicchains 7y ago
>so tired of having to hunt down what functions are going to return, sometimes having to resort to just using it
With highly generic functions, it's often not possible to know what they'll return without knowing what you'll call them with. Especially given that D functions like "map" and "reduce" tend to return special iterator types so that the compiler is able to smarty fuse them where possible. If D had concepts like C++20, you could probably describe them with something looking like:
template<class R>
concept __SimpleView = // exposition only
ranges::view<R> && ranges::range<const R> &&
std::same_as<std::ranges::iterator_t<R>, std::ranges::iterator_t<const R>> &&
std::same_as<std::ranges::sentinel_t<R>, std::ranges::sentinel_t<const R>>;
But at least for me that doesn't seem like it would be much more helpful than just reading the documentation, which states what the function returns, if not necessarily the type.
- rowanG077 7y agoSo you still can see that it depends on some input. That is hugely more useful then auto.
- asdkjh345fd 7y ago>With highly generic functions, it's often not possible to know what they'll return without knowing what you'll call them with. Of course it is. Map's type is "(a -> b) -> [a] -> [b]". D just absolutely and completely failed here, despite this being a solved problem 40 years ago.
- neutronicus 7y agoIt doesn't have to be specialized to []
- asdkjh345fd 7y agoOf course not. But it still has a type. Functor f => (a -> b) -> f a -> f b
- jcelerier 7y agono ? there are plenty of maps which don't return something which looks like [a] -> [b].
- asdkjh345fd 7y agoSo? They still have a type, it doesn't have to be "screw you figure it out yourself". Functor f => (a -> b) -> f a -> f b
- jhoechtl 7y agoRepeating the same over and over again doesn't make it any clearer for the ones trying to follow your line of argumentation. Seems like you had some deep exposure to Haskell, ML or Hindley-Milner in general which, when excessively consumed, detaches from reality. For one reason or the other you take this discussion serious and personal.
- asdkjh345fd 7y agoIf something is unclear, you can ask for clarification. I repeated the statement to three people because three people repeated the same argument to me. This is how conversations work. I have very limited exposure to haskell, am not detached from reality, and am taking nothing personal. Of course the discussion is serious, why would I spend time engaging in a frivolous and meaningless discussion?
- jcelerier 7y agocould you provide the type of this map function ? auto map(auto x) { if constexpr(is_same<decltype(x), int>) { struct T1 { int getStuff() { return 0; } }; return T1 {}; } else { struct T2 { void doStuff() { } }; return T2 {}; } }
- asdkjh345fd 7y agoRead the rest of the discussion.
- jbverschoor 7y agobeing a solved problem 40 years ago Ahh.. welcome to computer "science", the ever repeating cycle of 'inventions'
- atilaneves 7y agoNot in D, it isn't, for performance reasons. It takes an input range and returns a type that iterates through that range applying the callable (doesn't have to be a function!) to each element as requested.
- asdkjh345fd 7y ago>It takes an input range Which should have a type. >and returns a type that iterates through that range Which should have a type. The entire point is that this is a solved problem, there is no excuse to simply throw up our hands and say "screw documentation we'll just say this function is a mystery". Functor f => (a -> b) -> f a -> f b And please don't miss the point and tell me D doesn't have Functor. The entire point is that D has something, and it doesn't tell us what that something is. It should. Documentation is good.
- FeepingCreature 7y agoD has functors, but it doesn't have 'Functor'. Or rather, D doesn't have concepts (of which 'Functor' is a special case); that is, the notion of a type that is characterized by having the ability to execute operations is not expressible in its typesystem. Or rather, it is, but only with classes. You want something like "a return type; fulfilling the condition of being able to be used in this way." This is not something you can specify as a function attribute in D. Instead, ranges use a form of duck typing. The next step in the call chain can tell whether the previous step gave it something it can use using template inconditions, ie. `isInputRange!T`. But the previous step can't assert that it is returning a type that fulfills a constraint. In other words, there's type inconditions but not type outconditions.
- tomp 7y agoWhat you're describing has names - structural types, refined types (a.k.a. contracts a.k.a. pre- and post-conditions)... It's simply a failure of D the language/compiler (and a huge anti-pattern) to not expose internal types in a way that can be displayed to the programmer.
- GoblinSlayer 7y agoThat still means "it returns something".
- asdkjh345fd 7y agoIt gives us much more information than "something". It tells us it is a list of the type of the second argument to the function we passed it. Or in the generic version a "something you can iterate over" of things of the type of the second argument to the function we passed.