What are you working on, Sup Forums?
Last thread:
What are you working on, Sup Forums?
Last thread:
c++ is the greatest language of all time
Orthodox C++ is the One True Way.
What language would Hatsune Miku use?
I'm using python's defaultdict, the import from collections. Is there an easy way to make sure the dict's value never goes below zero? Some way to impose that hard limit?
Employed computer engineer here
Am I misinterpreting this?
Visual C++
Either
1. Just don't bring it below zero
2. Subclass defaultdict to throw an exception into your own face if you do it
2. Subclass defaultdict to silently discard negative values. This basically makes it a bag. Notice that this is a common pattern
Pick what makes sense.
let q = &p
Thanks! Noob here, what do you mean by subclassing? Make a new class that inherits from defaultdict, and add an extra function def that does this new behavior?
what do you mean by value? that the dict doesn't store any value
>Make a new class that inherits from defaultdict...
That's what sublassing is.
Almost. You would inherit defaultdict, but not in order to add a new method, in order to augment that method who's name I can't remember that's called when a key is assigned. Can you into super()?
whats computer engineer
I can't export my demo into an .exe file in blender
fuc u phyton
pls help
pic related
Better ask blenderfags tbf fampai
Is this a human or a robot job?
Why is /dpt/ so mad about types?
feels like pic
>His data is mutable
i am ANGRY about TYPES
Is Idris a lang for the cool kids?
Hatsune miku is my wife
only if you enjoy masturbating with types more than writing programs that actually get things done
who knows. these complaint do not even make sense. there is no such thing as programming without types.
Forth doesn't have types and it's Touring Complete
...
are there any valuable programming books?
not those ones that teach you useless quantum computing algorithms
mmm
it's not because they are implicit and you dont see them that they are not there
>No one cares.
If you're going to claim something is possible, I would like to request proof that it is possible. I currently doubt that it is possible.
>but that's due to JS only supporting OOP-style polymorphism.
My entire point is that Haskell's constraint-based parametric polymorphism is better than OOP-style polymorphism because it isn't constrained in this way. return shouldn't have to be a member of 'x'.
genericMaybeDiv :: MonadMaybe m => Float -> Float -> m Float
genericMaybeDiv x 0 = none
genericMaybeDiv x y = return (x / y)
function genericMaybeDiv(x, y) {
if (y == 0) { return ??.none(); }
else { return ??.return(x / y); }
}
Notice that we don't depend on a particular monad, we just require that it has a "none" and a "return" implementation. The solution to the javascript implementation of course is to pass a dictionary, like I said before.
Is there actual worth in checking for structural type equality?
as opposed to?
Don't try to explain virtual static methods to OOP zealot, it's too complex for them. At least some C++ can understand it, but that's all.
use Alternative or MonadPlus
none -> empty/mzero
>virtual static methods
Here we are. You just proved my point. That user was explaining how the forall quantifier works with monad by showing a virtual static method, but the JS dev failed to understand.
Name type equality?
Just in case I'm getting some terms wrong, I mean that if you've got a type Vector that's an array of ints, a type Number that's an int, and a type Vector2 that's an array of Numbers, structural type equality would be that they are the same based on the structure. Name equality would be that they're not the same, because their names aren't the same.
But I'm wondering if there's any actual point to checking for structural equality.
They're called polymorphic functions.
>I would like to request proof that it is possible
I already gave you a proof that it is possible using OOP-style polymorphism:
function muhGenericMonadicValueAdder(x, y) {
return x.bind(function(a) {
return y.bind(function(b) {
return x.ret(a + b);
});
});
}
If you don't like OOP methods (which I can relate to), there are other ways to do dynamic dispatch, like multimethods, which look like ordinary function calls, and don't imply the function being a "member" of the type of the value being dispatched on.
>My entire point is that Haskell's constraint-based parametric polymorphism is better than OOP-style polymorphism because it isn't constrained in this way
I agree, but multimethods aren't constrained in that way, either.
>Notice that we don't depend on a particular monad
Neither does the code above, which I already posted in the previous thread.
> The solution to the javascript implementation of course is to pass a dictionary
Consider not lying so blatantly.
A standard-compliant Forth runtime doesn't check any types, but you are free to extend the runtime and add a type checker.
No. Polymorphic functions are something else. There is a forall quantifier, but only on the type of the arguments, not of the type owning the function.
>I already gave you a proof
No, I want proof that multimethods will somehow give you a generic return (generic as in generic over which monad we are using) that doesn't require an existing instance of the monad. E.g. finish implementing my JS code, without adding a new argument to genericMaybeDiv
>Neither does the code above
Your code is fundamentally different from mine, since yours has instances of the monad available, and mine does not.
>Consider not lying so blatantly.
Consider actually reading my post.
>There is a forall quantifier, but only on the type of the arguments [and return], not of the type owning the function.
So exactly like this?
class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
>forall m. Monad m => (...)
this triggers the rustaceans
A type theorist would claim that forth simply has only one type, that is the type of fixed width integers. And forth documentation implies a small implicit type system, by denoting when certain functions are expected to take numbers as input, and other functions are expected to take pointers or strings (pointer + length)
Not the best example, but yes. It's far more powerful than polymorphic function. OCaml has polymorphic function, but to reach the level of forall quantifier of Haskell you need functors.
Higher kinded polymorphism is polymorphism.
Theoretically OCaml could have had higher kinded polymorphism, but HKTs are actually very useless without typeclasses, which OCaml certainly lacks.
This is entirely beside the point. Higher kinded polymorphism is not more powerful than polymorphism because it is polymorphism, and it certainly has nothing to do with "types owning functions" or "virtual static methods".
I am livestreaming C++/Common lisp programming on my channel. I am writing a Content Delivery Network that will use torrents. right now I am debugging my pre-alpha code, check it out! youtube.com
That's polymorphism, but that's not really what we call polymorphic function, but OK, you're right, I won't argue.
I would say it is more powerful because it allows you to abstract over more things than not-higher-kinded polymorphism.
>has nothing to do with "types owning functions" or "virtual static methods".
Not in a vacuum, but most practical uses of HKT's involve these concepts.
>virtual static methods
That's exactly what you do when you write
test :: MonadAdd m => m a
test = mzero
mzero is what we could call "static virtual method" in OOP world.
If you interpret "polymorphism" as "not higher kinded polymorphism" then that's your problem.
nice
>Your code is fundamentally different from mine, since yours has instances of the monad available, and mine does not.
Oh, I see what I'm missing now. Yeah, yours requires type inference, not just static typing.
i want to fug migu
Well polymorphism is certainly a broad term that can be applied to a lot of aspects of a type system
rust
>java
>programming
>no keyboard
When I overload ==, why do I also have to overload != ?
It doesn't make sense to me, if it's not equal, it's... well "not equal", that's the whole point of boolean logic.
Please enlighten a brainlet like myself.
hi
real men use an on-screen keyboard
scheme
In C++, yeah.
It's stupid, but you can do something as simple as this.
bool Foo::operator!=(Foo const &other) const
{
return !(*this == other);
}
sepples?
I'm still getting used to C++.
When/where should I use new to create an object? For instance, should I use it to initialise a vector which is a member of an object?
How exactly does creating objects on the stack work? For instance making an object in a method and returning it doesn't seem to pop it from the stack but I thought that's how it worked.
Why the FUCK would you learn C++ when there's C89?
the absolute state of sepples
*Rust
Well I'm using C#.
But I guess my question holds for C++ too.
never use new
compiler can optimize things how it sees fit
if you allocate on the stack, it will certainly be deleted the moment it is no longer accessible
>When I overload ==, why do I also have to overload != ?
Because someone thought it would be a good idea to let C++ coders abuse these operators for things completely unrelated to boolean logic.
Use the stack as much as possible.
Use the heap when an object needs to live longer than the scope which created it and a move is not acceptable, or when you need a buffer of size not known at compile time.
Returning an object is cool because the object is passed by value. If you were to return a pointer or reference to an object created in that function's scope, that would break.
I thought C# "fixed" that hole.
Hello guise,
I think ima start doing this: web.stanford.edu
Apperently the library of my uni has no rust books available and I have never ever programmed in rust.
Any good sources to learn it?
A a;
B b;
std::cout leaks memory, spawns nasal demons, sends your browser history to botnet
in Haskell you don't have to
C++ wants you to define all the operators.
but libraries can help synthesize the missing operators from a few of them. see boost.operators
>Has a doll of herself on her desk
What a fucking narcissist.
>learning rust
that's a really bad idea
oh it even has a link to that rust tutorial thingy. nvm then.
Why?
Won't that impact clock signal distribution, resistance and capacitance and whatnot? I'm a bit surprised it works fine with such radically different wire lengths.
You have to borrow from p not o.
I was asking about model view controller a few days ago.
pastebin.com
Is this a correct model view control set up? Specifically this part
public partial class frmCalcView : Form, ICalcView
{
Controller controller;
Is the view allowed to have the controller there?
This isn't mine I got it from codeproject.com
looks fine to me
Alright, I was just confused when I read about mvc and how it says all the parts don't depend on each other. I can understand it for the model but I didn't understand it for the view since you would need some kind of listener to deal with the buttons and stuff. What do they mean by views are easily swappable? In my mind when you make a gui it's usually drag and drop with blank listener functions, how can you easily swap a view with 1 button to a view with 2 buttons without changing the code?
Yeah, ought to be fine.
The way I've been taught MVC is that listeners are implemented in the view, and call functions on the controllers. Those functions on the controller should be able to handle input from the different views.
bool operator==(A a, B b) {
while (true) {
char* memory = std::malloc(1000);
}
}
private void lblPlus_Click(object sender, EventArgs e)
{
controller.OnAdd();
}
So basically like this then, sometimes I just get stuck on really dumb basic stuff.
Thanks.
My program has a vector which holds vectors of a different object type, and I'm getting loads of trouble loading up the vectors and pushing them onto the 2D vector. None of them are allocated through new (including the temporary vectors initialised through iterations of a for loop) so I don't know if that could be the problem.
Yup. I get you, though, it didn't really click for me either at first.
>not using a recursive template so the compiler eats all the memory for you
Can you post the code?
that's fine to do, so there's an error in your code somewhere, maybe you aren't constructing the objects properly
What's the best resource for learning C# and .net?