255 karma · joined June 2, 2012
trait Bounded {
fn min_bound() -> Self;
fn max_bound() -> Self;
}
Which can be used like so. Using type inference. fn add_min_to_set<T:Bounded, S:MutableSet<T>>(set: &mut S) {
set.insert(Bounded::min_bound())
}
Or you can be more explicit let mut i: u8 = Bounded::min_bound();
while i < Bounded::max_bound() { println!("{}", i); i += 1; }
Edit: spacing, s/++/+= 1/So the Bounded typeclass is defined as
class Bounded a where
minBound :: a
maxBound :: a
If you have a function and you want the argument to be Bounded you write allLessThan :: (Enum a, Bounded a)=> a -> [a]
allLessThan x = [minBound..x]
Here `a` is a generic type. That implements the Enum and Bounded typeclass. You could just write `allLessThan x = [minBound..x]` and Haskell with infer the type classes by itself.To implement the typeclass you use `instance`, like so:
data MyType = A | B | C | D
instance Bounded MyType where
minBound = A
maxBound = D[1] NaR will propagate an error, but trigger an exception if it's stored or branched on.
Why do those routers have open telnet interfaces.
f = os.NewFile(3, "/dev/zero") # Go
you would use f = os·NewFile(3, "/dev/zero"); # C int abs_s(int x) {
assert(x != INT_MIN);
return (x >= 0) ? x : -x;
} max(a++, b--)
Which expands to ((a++)>(b--)?(a++):(b--))
creating unexpected results. The solution is, don't use return values of `++` and `--` in calls, unless you know it's a function, and always will be. Upper-case macros may help, but then you need to make sure all macros are upper case.Now we also have "plain packaging laws" which means packets cannot have the Tobacco companies design on it. They must be olive green and have government anti-smoking ads, and the product name in plaintext.
He found it was very good for cross platform work.
> __restrict is similar to restrict from the C99 spec, but __restrict can be used in C++ or C programs.
Could not find compiler set in environment variable CC:
gcc-4.8.
I'm running gcc-4.9. I got it working by doing: ln -s /usr/bin/gcc ~/bin/gcc-4.8
ln -s /usr/bin/g++ ~/bin/g++-4.8
I'm not saying this is good practice, but it works.Also need to make sure python means python2.
func mustBeNil(err error) {
if err != nil {
panic(err)
// or log.Fatal(err)
}
}
or func mustBeNil(err error, msg string) {
if err != nil {
log.Fatalf("%s: %s", err, msg)
}
}
;Edit: brackets1. New Zealand 2. South African 3. Australian.
With native languages as
1. English 2. Chinese 3. Greek
I'm English speaking Australian. So it got very close.
It can be really confusing when all three are somewhat popular in one country.
func Polar(x complex128) (r, θ float64) {
return Abs(x), Phase(x)
}
It seems to be good for documentation reasons.Like Go and Dart?