5 ms·
Look how nice and concise and readable the F# or even the Pure Basic examples are compared to Rust.
by fortran77 7y ago
Look how nice and concise and readable the F# or even the Pure Basic examples are compared to Rust.
- vore 7y agoDifferent languages, different guarantees, different uses :)
- unhammer 7y agoThe C# one must be trolling
- rpeden 7y agoThe first two C# solutions come closer to actually implementing Amb, though. The Purebasic solution depends on the operands being strings, and the F# solution depends on them being sequences. And the way that the 'Ambassert' works in both of them is hardcoded, too. Since the problem was 'create an Amb implementation and demonstrate it using the data below' and not 'create an Amb-like thing that can only solve for cases where the operands are strings/sequence and the last item in operand 1 must match the first item in operand 2', I believe that the C# solutions actually solve the problem, while the Purebasic and F# solutions do not.
- tigershark 7y agoThe C# classes solutions are doing the same thing as the F# solution, but in a more complicated way. You don’t really need the Amb operator to solve that problem using the list monad or list comprehension or doing a join. I’ve never seen anyone complain that you should have an Amb operator in SQL when you are doing a JOIN.
- Dylan16807 7y agoThe PureBasic and Rust versions don't seem valid to me. They each have a so-called "Amb" function that can only process lists of words that start and end with the same letters. And if they can't even get the prompt right, I wouldn't trust how well they act as examples of their respective languages. The F# version... it's okay, I guess, but the fully-functional "declare all variables at the start, then filter" style is definitely easy mode. It's not really comparable to an 'Amb' that properly supports imperative code, letting you declare ambiguous variables, compute things with them, then use those computations to declare more ambiguous variables.
- rpeden 7y agoThe F# version doesn't really implement Amb either. It's similar to the PureBasic and Rust versions in that it can only work on sequences by checking that the last item in sequence #1 is the same as the first thing in sequence #2. If I'm reading the page correctly, the task is to create a general Amb implementation and merely demonstrate it using the data provided, and not to create a solution that only works on data similar to the sample data. So I don't believe any of the PureBasic, Rust, or F# solutions meet the requirements. Though since it's a wiki, someone might have gone in and edited/added to the solutions after I wrote this. :) In comparison, the class-based C# solutions are a lot more verbose but appear to actually solve the problem that was defined.
- Dylan16807 7y agoThe F# version isn't that limited. You can replace the 'if' with arbitrary logic, and that 'if' is outside of the amb 'implementation'. It can do lots of different computations with that structure. But there's no straightforward way to do things more complicated than a series of amb declarations followed by a series of amb asserts.
- tigershark 7y agoIt’s because you don’t actually need the Amb operator to solve that problem with list comprehension and the list monad. Adding it it’s just superfluous. The C# classes solution may meet the requirements but I still think that my csx solution (kind of similar to the Haskell, F# and python list comprehension) is more compact and readable.
- giornogiovanna 7y agoHopefully this version's closer to the prompt.[0] Anyway, the F# code, IIUC, lets you do exactly what you want it to do, although you'd have to replace the ifs with guards. [0]: https://rosettacode.org/wiki/Amb#Monadic https://rosettacode.org/wiki/Amb#Monadic