These are chat archives for rust-lang/rust

31st
Jul 2017
lemonxah
@lemonxah
Jul 31 2017 08:49
good morning
        fn sum<A, F>(v: F) -> A where A: Monoid, A: Semigroup, F: Foldable<A, A=A> {
            v.fold(A::mempty(), |b, a| A::mappend(&b, a))
        }
is there a better way of saying that A: Monoid and Semigroup?
other than having to have the semigroup function be part of the Monoid
Denis Lisov
@tanriol
Jul 31 2017 08:50
Are Monoid and Semigroup independent, or does one require the other?
lemonxah
@lemonxah
Jul 31 2017 08:50
Monoid requires Semigroup
but Semigroup has teh mappend function and Monoid the mempty
Ilya Bogdanov
@vitvakatu
Jul 31 2017 08:50
A: Monoid + Semigroup
lemonxah
@lemonxah
Jul 31 2017 08:51
and what if they were independent?
just want to know the syntax change
thank you btw :)
Denis Lisov
@tanriol
Jul 31 2017 08:51
Then you should probably define Monoid as pub trait Monoid: Semigroup { ... }
lemonxah
@lemonxah
Jul 31 2017 08:52
monoid is defined that way
Denis Lisov
@tanriol
Jul 31 2017 08:52
Then you shouldn't need to require A: Semigroup specifically, as A: Monoid already implies that.
lemonxah
@lemonxah
Jul 31 2017 08:53
pub trait Semigroup: Clone {
    fn mappend(self: &Self, other: &Self) -> Self;
}

pub trait Monoid: Semigroup {
    fn mempty() -> Self;
}
it complains that mappend is not part of A
oh nvm
:/ it seems to be working now
maybe i was high when first testing it :)
thank you anyway
when you impl X for A does that mean that impl is now always in scope and i dont have to import it in some way?
Zakarum
@omni-viral
Jul 31 2017 08:57
@lemonxah you only need to have module with impl within your crate
lemonxah
@lemonxah
Jul 31 2017 08:57
so its almost like typeclasses?
Zakarum
@omni-viral
Jul 31 2017 08:58
Very similar
lemonxah
@lemonxah
Jul 31 2017 08:58
but let say i have a Show typeclass and i want multiple impl for the same type but i want to choose which one is in scope?
Zakarum
@omni-viral
Jul 31 2017 08:58
No. You can't have multiple instances
Except
They do not get compiled at the same time
You can have different impls for debug and release for example
lemonxah
@lemonxah
Jul 31 2017 09:00
oh ok
still trying to get used to this typesystem
i have seen stuff like Foldable<A, A=A> and that works for my HKT type that i found on some gist
and i am guessing that it says the inner type A should be equal to the outer type A
Zakarum
@omni-viral
Jul 31 2017 09:02
Assotiated type named A is A
lemonxah
@lemonxah
Jul 31 2017 09:02
but its a bit foreign for me its the first typesystem i see that you have to do that
Zakarum
@omni-viral
Jul 31 2017 09:02
Yes
Sherab Giovannini
@Shaddy
Jul 31 2017 10:08
does anyone managed to debug tests in osx with vscode?
L. Preston Sego III
@NullVoxPopuli
Jul 31 2017 18:11
anybody use Helix? or develop for Helix?
Chris Garrett
@pzuraq
Jul 31 2017 18:34
Are there any major differences in using GDB vs LLDB?