4 ms·
It's 30 lines long (the equivalent in Haskell would be 1 fairly simple line of code). Type errors are detected at runtime instead of at compile type, and it's n
by TheCoelacanth 12y ago
It's 30 lines long (the equivalent in Haskell would be 1 fairly simple line of code). Type errors are detected at runtime instead of at compile type, and it's not as generic as actual reduce.
- istvan__ 12y agoIn fairness not only in Haskell. I think Go is just not a great choice for this sort of effort. On Haskell though, languages are not a single dimension thing, so it is very easy to say that X is better in Y and leave out all the other dimensions, but that just oversimplification of the problem.
- falcolas 12y ago> It's 30 lines long (the equivalent in Haskell would be 1 fairly simple line of code). Bully for Haskell. Language N can always do it better/faster/shorter than language M. What matters in this case is that it can be done, in a type safe way. > Type errors are detected at runtime instead of at compile type Already mentioned that. > it's not as generic as actual reduce. It's toy code, forgive him for not writing it perfectly. If it can accept one ambiguous type throughout, there's no reason it could not accept multiple types throughout.
- TheCoelacanth 12y ago> If it can accept one ambiguous type throughout, there's no reason it could not accept multiple types throughout. I'm sure it could, but only at the expense of ballooning to an even more disproportionate length.
- falcolas 12y ago> I'm sure it could, but only at the expense of ballooning to an even more disproportionate length. If you looked at the code, you would see that it could be done in zero additional lines of code if he wanted, or in one if he wanted to be explicit. if !goodFunc(fn, elemType, zero.Type().Elem(), elemType) { str := elemType.String() panic("apply: function must be of type func(" + str + ", " + zero.Type().Elem().String() + ") " + str) } There would be a few other inline changes to add `zero` to the function calls (and fix the 0/1 cases), but they are all pretty trivial. If we want to be pedantic about it, the goodFunc call is not even technically required, it just makes the error output a bit better.