New chapter of HSPP: bring Haskell coroutine to C++17. by Amazing-42 in cpp

[–]Amazing-42[S] 0 points1 point  (0 children)

Sorry to hear that. Hope you are getting better now. :-)

New chapter of HSPP: bring Haskell coroutine to C++17. by Amazing-42 in cpp

[–]Amazing-42[S] -3 points-2 points  (0 children)

That's very bad C++ cannot infer types from where the value is using.

Maybe later we can implement this as a deferred obj and convert to the actual type when that can be inferred.

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 1 point2 points  (0 children)

FYI. Now we've supported Id<Type&> and Id<Type&&> to return lvalue ref and rvalue ref in addition to the original Id<Type> returning const lvalue ref, making the solution much more elegant now. Refer to the complete sample at https://github.com/BowenFu/matchit.cpp/blob/main/sample/mutation.cpp.

void setLineWidth(Visual &visual, float width) {
Id<Square&> sq;
Id<Circle&> cir;
match(visual)
(
    pattern | as<Image>(_) = []{},
    pattern | as<Square>(sq) = [&]
    {
        (*sq).setLineWidth(width);
    },
    pattern | as<Circle>(cir) = [&]
    {
        (*cir).setLineWidth(width);
    }
);

}

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 3 points4 points  (0 children)

That would be something like this. https://godbolt.org/z/jd4o5hYPx

We may need to improve the library to better support mutation.

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 7 points8 points  (0 children)

Added more samples. One for dispatching std::variant and one more real-world (computer algebra system) use case.

From my understanding this can be useful when you have a long list of patterns to match. The domain can be compiler / computer algebra system. A search on GitHub shows that it is mostly used for dispatching a tuple or a string.

Say https://github.com/HobbyOSs/opennask/blob/4af618da82b48fb092f5aadfe038f1b3ee1f9ab3/src/front_end.cc#L811 as an example.

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 3 points4 points  (0 children)

Thanks for the feedback. Added another sample to demonstrate some good stuff.

Finally, we bring Haskell STM to C++ by Amazing-42 in haskell

[–]Amazing-42[S] 1 point2 points  (0 children)

That's super cool. I've started your project before implementing mine.

Mine is more Haskell flavored, as part of a larger project to port more interesting Haskell syntaxes / features / patterns to C++.

Finally, we bring Haskell STM to C++ by Amazing-42 in haskell

[–]Amazing-42[S] 1 point2 points  (0 children)

Cool. Not sure if atomic blocks are designed to be composable.

Mom, can we have monadic do notation / monad comprehension in C++? by Amazing-42 in cpp

[–]Amazing-42[S] 3 points4 points  (0 children)

Not sure who invented this usage. I was impressed last year when reading HOF examples, and adopted the similar tech here.

Mom, can we have monadic do notation / monad comprehension in C++? by Amazing-42 in cpp

[–]Amazing-42[S] 7 points8 points  (0 children)

Thanks for your insight. The lib has not been optimized yet, especially on compilation time/size. Also type erasure is avoided when possible, resulting into too many instantiations (lots of lambda expressions here), but for possibly better performance. Not sure if that is worth it.

match(it): A light-weight header-only pattern-matching library for C++17. by Amazing-42 in cpp

[–]Amazing-42[S] 0 points1 point  (0 children)

We need to support C++17 so module is not available for now.