These are chat archives for boostorg/hana

4th
May 2015
Manu Sánchez
@Manu343726
May 04 2015 15:27
Hey, I finally got gcc-clite working. The latest release (gcc-clite 0.3) starts from GCC 4.8.0, so I'm not sure if this will work with hana since it relies on C++14. I will check the GCC features table now.
polymorphic lambdas 4.9 ;(
Louis Dionne
@ldionne
May 04 2015 15:27
No, it will definitely not work with Hana. Actually, I’m working on a port of Hana for GCC 5 but it’s still not done.
Anything below GCC 5 is very unlikely to work. I’ve tried it before, but we have to reduce the functionality so much that it becomes less usable. For example, no generalized constexpr and no variable templates basically destroys Hana.
But GCC5 got all that, hence the ongoing port.
Manu Sánchez
@Manu343726
May 04 2015 15:32
I haven't found any other experimental implementation of concepts lite. Nothing from the llvm guys.
Louis Dionne
@ldionne
May 04 2015 15:33
Crap
Manu Sánchez
@Manu343726
May 04 2015 15:34
There is a thread at the iso c++ google groups list on the topic: https://groups.google.com/a/isocpp.org/forum/#!topic/concepts/uNVfp04qN64
Louis Dionne
@ldionne
May 04 2015 15:34
Hmmm… Would there be a way to prototype something without using Hana per-se? E.g. implementing a similar framework, but naively, which would reduce the complexity of implementing it from scratch by a lot?
Manu Sánchez
@Manu343726
May 04 2015 15:36
Well, defining a library of concepts using Concepts Lite, and then add those to Hana in the future sounds great for me.
Louis Dionne
@ldionne
May 04 2015 15:36
Basically, what we’re talking about is implementing Hana’s concept hierarchy (or a similar one) using concepts lite instead of my ad-hoc tag-dispatching system, right?
Manu Sánchez
@Manu343726
May 04 2015 15:37
Right
Louis Dionne
@ldionne
May 04 2015 15:37
And then see if we’re able to handle both compile-time and runtime stuff through it?
Manu Sánchez
@Manu343726
May 04 2015 15:37
Yep
Louis Dionne
@ldionne
May 04 2015 15:39
Ok, we’re on the same page. Then, it should suffice to consider a very much simplified version of Hana. Basically, it would be useful to see if you’re able to handle compile-time optionals (hana::Maybe) and compile-time sequences (hana::Tuple) through such a hierarchy, but no need to define 1000x algorithms like hana::Sequence does.
Manu Sánchez
@Manu343726
May 04 2015 15:39
Looking at your implementation, Hana internals are mostly C++11. Template variables, generic lambdas, etc are more part of the user side, right?
Louis Dionne
@ldionne
May 04 2015 15:41
There’s also generalized constexpr and automatically deduced return type, which are quite important.
But if we’re only considering a barebones frame of the library, without providing a lot of algorithms, we might be able to reduce the requirements to C++11.
Manu Sánchez
@Manu343726
May 04 2015 15:44
Let's translate your existing concepts to gcc-clite then, and see how they work.
Louis Dionne
@ldionne
May 04 2015 15:44
Yeah, I think that’s the way to go.
Manu Sánchez
@Manu343726
May 04 2015 15:45
We could get concepts from range_v3 too.
Louis Dionne
@ldionne
May 04 2015 15:47
Probably, but I’m not too familiar with the proposal since I’ve been working on Hana. One thing that will probably hurt is the presence of iterators and sentinels. Since we want to have type sequences, an iterator should “point to a type”. When you increment it, the type it points to must change, and so the type of the iterator itself must change. This precludes stuff like iterator++.
Manu Sánchez
@Manu343726
May 04 2015 15:48
Okay, let's get simple and start with Hana only.
Manu Sánchez
@Manu343726
May 04 2015 17:06

I don't know what OS/distro you use for development. I'm an ArchLinux guy, so I have submitted a gcc-clite package to the repository: https://github.com/Manu343726/gcc-clite-aur

$ yaourt  -S gcc-clite

should work. It builds gcc from scratch, so be patient and go for a coffee :)

Louis Dionne
@ldionne
May 04 2015 17:06
I’m on OS X :worried:
I should be able to simply build it by hand
Manu Sánchez
@Manu343726
May 04 2015 17:10

Check sources https://github.com/Manu343726/gcc-clite-aur/blob/master/PKGBUILD It's just a plain call to gcc configure script plus some sed replaces to fix issues related to the legacy texinfo version they are using for the docs.

mkdir build 
cd build

# Patch texinfo >= 5.0 issues. See https://gcc.gnu.org/bugzilla/attachment.cgi?id=29520&action=diff
sed -i -- 's/@itemx/@item/g' ../gcc-clite-0.3/gcc/doc/*.texi

# Configure (Note --disable.werror)
../gcc-clite-0.3/configure --disable-werror --program-suffix=-clite --program-transform-name='s/^gcc$/gcc-clite/g' --enable-languages=c++

make
make install

Check GCC install docs too.

Louis Dionne
@ldionne
May 04 2015 17:10
Yeah, I think I’ll be OK. I already have a GCC trunk so I’m familiar with the process (but the first time I did it was f*cking painful).
Louis Dionne
@ldionne
May 04 2015 18:07
@Manu343726 I’m building GCC-clite right now; everything seems fine so far.
Manu Sánchez
@Manu343726
May 04 2015 18:10
I'm testing concepts with Turbo. This is so awesome
definitely concepts are the right way to go for algebraic datatypes and typeclasses
Manu Sánchez
@Manu343726
May 04 2015 18:16
There is no fancy "X does not satisfy Y concept" error message though. Just ignores the template. At least there's no 100k lines error like with SFINAE.
Louis Dionne
@ldionne
May 04 2015 18:16
Exciting.
Can you put your experiments in a repo so I can watch it?
Manu Sánchez
@Manu343726
May 04 2015 18:25
sure. I'm playing with Turbo datatypes now. I have added a concepts-lite branch, file examples/main.cpp.
Louis Dionne
@ldionne
May 04 2015 18:26
Cool, thanks.
Manu Sánchez
@Manu343726
May 04 2015 18:27
Note the order of concept parameters. It feels reversed for me.
Louis Dionne
@ldionne
May 04 2015 18:33
I don’t get it. What do you mean?
Manu Sánchez
@Manu343726
May 04 2015 18:35
Binary concepts such as Comparable<T,U> can be used explicitly via a requires Comparable<T,U> expression. The shorthand is template<Comparable<U> T>
I feel that should be template<Comparable<T> U>...
Louis Dionne
@ldionne
May 04 2015 18:36
Oh, I get it.
Louis Dionne
@ldionne
May 04 2015 18:43

Is it possible to constrain template-template parameters with concepts? Imagine the following (flawed) constraint:

template <typename Xs>
constexpr bool Foldable() { return ...; }

template <Foldable Xs>
constexpr decltype(auto) sum(Xs&& xs) {
    return foldl(xs, 0, _ + _);
}

Instead, the correct thing to write would be

template <template <typename> class Xs>
constexpr bool Foldable() { return ...; }

template <typename T>
constexpr bool Monoid() { return ...; }

template <Foldable Xs, Monoid T>
constexpr decltype(auto) sum(Xs<T> /* perfect forwarding magic */ xs) {
    // we also need to define the 0 and + of the Monoid
    return foldl(xs, 0, _ + _); 
}
Is this possible?
Manu Sánchez
@Manu343726
May 04 2015 18:54
It works! Seems like any kind of template parameter is allowed
Louis Dionne
@ldionne
May 04 2015 18:57
Awesome. I think Hana could benefit a lot from concepts. It could make a lot of tag-dispatching issues like the need to write sum<int> go away.
Manu Sánchez
@Manu343726
May 04 2015 18:58
template<template<typename...> class T>
constexpr bool Template() { return true; }

template<Template T>
struct foo
{
    using type = T<int>;
};
Bye bye ugly template-template parameters.
Louis Dionne
@ldionne
May 04 2015 18:59
lmfao
Wut wait.
Universal non-type template params?
template <typename T>
constexpr bool Integral() { 
    return T is in {int, char, long, ...}; 
}

template <Integral i> 
struct foo { };
Manu Sánchez
@Manu343726
May 04 2015 19:02
Whaaaaaaaaaaaaaaaaaaaaaaaaaaat?????????? Wait wait wait.
Louis Dionne
@ldionne
May 04 2015 19:02
I don’t know, I’m just throwing stuff around. My GCC-clite is still compiling :)
Manu Sánchez
@Manu343726
May 04 2015 19:06
Nooooo, it expects a class :(
Louis Dionne
@ldionne
May 04 2015 19:07
Too bad.
Anyway, I have to go for a bit, bye.
Manu Sánchez
@Manu343726
May 04 2015 19:08
Bye
Manu Sánchez
@Manu343726
May 04 2015 19:26
It's explained on the examples http://concepts.axiomatics.org/~ans/
The implementation only does constraining on types. Note he is still using template functions.