News for hackers. Stuff that matters.
Re:Amb by fortran77 on Saturday February 22, 2020 @02:03AM (#22389801)
Look how nice and concise and readable the F# or even the Pure Basic examples are compared to Rust.
Re:Amb by Dylan16807 on Saturday February 22, 2020 @04:52AM (#22390191)
The 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.

Re:Amb by rpeden on Saturday February 22, 2020 @12:49PM (#22392244)
The 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.

Re:Amb by Dylan16807 on Saturday February 22, 2020 @12:54PM (#22392283)
The 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.
Re:Amb by tigershark on Saturday February 22, 2020 @11:11PM (#22395096)
It’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.
Re:Amb by giornogiovanna on Monday February 24, 2020 @12:32AM (#22401905)
Hopefully 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

Re:Amb by vore on Saturday February 22, 2020 @02:14AM (#22389824)
Different languages, different guarantees, different uses :)
Re:Amb by unhammer on Saturday February 22, 2020 @03:16AM (#22389960)
The C# one must be trolling
Re:Amb by rpeden on Saturday February 22, 2020 @12:40PM (#22392201)
The 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.

Re:Amb by tigershark on Saturday February 22, 2020 @11:16PM (#22395111)
The 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.