[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 332
Thread images: 26

File: free monad example.png (89KB, 692x800px) Image search: [Google]
free monad example.png
89KB, 692x800px
What are you working on, /g/?


Previous Thread: >>56545311
>>
First for Haskell
>>
haskell is bad and you should FEEL bad!
>>
>functions in his favorite programming language can only fave one argument

Top
Kek
>>
Linear types can make imperative code pure.
>>
>>56555145
>his language doesn't have MUH MONADS
>>
Mercury is so pure, she will help you restore your anal virginity.
>>
>>56555148
I don't know what that is, so I'm certain it's wrong.
>>
>>56555148
They don't give you the composability or first class nature that monads have
>>
File: 1374270278532.jpg (75KB, 597x800px) Image search: [Google]
1374270278532.jpg
75KB, 597x800px
Asking one more time:
Does anyone know how strong the 4chan API rules are enforced?
Especially the rule
Do not make more than one request per second.
.
>>
>>56555145
>hurr durr currying

Also
http://okmij.org/ftp/Haskell/polyvariadic.html#polyvar-fn
>>
>>56555171
Monads kind of have two uses. The first would be sequential composition and the second would be standing in for linear types. Monads are great at doing the first thing, but I'd like to have the real thing when it comes to linear types as well.
>>
>>56555159
>he's unable to explain what a monad is without using obscure mathematical terms
>he'll fail like the dozens other haskell devs who failed before him
>>
File: 1466786699974.jpg (213KB, 1195x1500px) Image search: [Google]
1466786699974.jpg
213KB, 1195x1500px
can I just get a small, informal survey going? I just want to know if you are a professional, making a living off of your coding, a student hoping to become a pro, or just a hobbyist doing it for kicks. That's all. THanks!
>>
>>56555195
POO
>>
I'm working on a constant pool editor for java. Currently reading the class file is done, but saving it (data back to butes) still needs to get done.
>>
File: 1470521334454.jpg (50KB, 633x758px) Image search: [Google]
1470521334454.jpg
50KB, 633x758px
I'm really fucking angry. I spent ages looking at an lg smart tv api for a project of mine and got everything all comfortable only for life to shit all over me because lg introduced a new messaging protocol recently.
>>
File: 2016-09-11_17-51-33.png (566KB, 1683x463px) Image search: [Google]
2016-09-11_17-51-33.png
566KB, 1683x463px
Trying to go for my VMware vSphere Cert. Got my lab setup. I basically setup nested virtualization (ESXi Hosts running on VM's). Works ok, for a lab.
>>
>>56555202
>and the second would be standing in for linear types
Not true, and linear values again force stuff on the language like strict ordering.
>>
Which is faster?

String x="dicks";


or

String x=new String("dicks");
>>
Friendly reminder compilers for almost every language should be able to evaluate pure functions at compile time.
>>
>>56555261
First one. Allocating memory on the stack is just moving the stack pointer. Allocating on the heap is more complicated
>>
File: 1468803542652.png (761KB, 1205x1643px) Image search: [Google]
1468803542652.png
761KB, 1205x1643px
it's impossible
>>
>>56555263
this, fucking smug haskell tards
>>
>>56555263
But what if a "pure" function isn't really pure?
>>
>>56555297
Then it's not a pure function.
>>
>>56555256
Monads force strict ordering you dunce.
>>
>>56555252
>encoding/binary.Read can do it with a struct passed by interface{}, so there is no reason you why you can't do the same thing, applied by a slice of blank interfaces as []interface{}
then go read their implementations?
https://golang.org/src/encoding/binary/binary.go#L158
>>
>>56555412
Not on the entire language and all its expressions which is the exact point
>>
>>56555514
Not everything needs to be linear.
>>
>>56555522
Making everything linear is better.
>>
>>56555522
So use monads and do notation.
>>
>>56555577
Monads force LIFO without insane workarounds.
>>
>>56555593
What do you mean LIFO?
>>
>>56555613
Create resource A
Create resource B
Destroy resource A
Destroy resource B
>>
>>56555613
Last In, First Out.
>>
>>56555640
RAII?
>>
Is there any portable way to create structs at the runtime that are compatible with the ones created at compile time?
>>
>>56555648
What's that got to do with monads in general?
>>
>>56555649
What?
>>
>>56555657
It doesn't have to do with monads in general, it has to do with using monads to approximate linearity.
>>
>>56555656
They're contiguous

>>56555660
"resource aquisition is initialisation", but it's also a term for more stuff
like using smart pointers in C++ or similar (using constructors/destructors for acquiring and releasing resources in general)
>>
>>56555640
That's FIFO you fucking inbred
>>
>>56555686
RAII implies creating and destroying resources but not the other way around.
>>
>>56555685
Who said anything about approximating linearity?
The argument was about someone who said "use linear types rather than monads"
>>
>>56555703
Yes, I should have made it more clear that because that is ~not~ LIFO, monads struggle with it.

>>56555707
Because monads only approximate linearity.
>>
>>56555706
Creating and destroying resources around a given block of code is what you'd call RAII
>>
>>56555724
>Because monads only approximate linearity.
Nobody asked for linearity.

And you can get linear values from dependently typed monads
>>
>>56555725
Where do you see any blocks of code in that post? RAII is really only relevant when you have panics or exceptions.
>>
>>56555686
>They're contiguous
But there are stuff such as alignment that one should have in mind, as well as weird architectures and bitfields.
>>
>>56555744
Between monads and linearity, linearity is the one that's actually useful. So you should be asking for it.
>>
>>56555744
>Nobody asked for linearity.
Salty bitch. I already said monads are useful for composition, but linear types are better at sequencing (preventing aliasing).

>And you can get linear values from dependently typed monads
How so?
>>
>>56555747
>RAII is really only relevant when you have panics or exceptions.
Not remotely true

>>56555782
>>>oh I guess they can APPROXIMATE linear values -heh-"
>>who asked for that

>Salty bitch

>>And you can get linear values from dependently typed monads
>How so?
You can create an arbitrary DSL and enforce arbitrary requirements with dependent typing - e.g. "don't refer to this var again"

>>56555771
>monads aren't useful
I can tell you don't use them
>>
I swear Haskel fags are just as bad as idolfags. They won't stop harping about muh purity, muh purity. Just use slut functions like a real man, faggots!
>>
>>56555173
It's probably not particularly monitored, but you really shouldn't exceed the 1 request per second rule. Who knows what 4chan is running on these days - it might be an even older model of a mac mini ever since Japanese moot took over.
>>
>>56555834
>marry a slut function
>she fucks other men
cucked again ;_;
>>
>>56555120
Holy shit, this language is unreadable. I'll never leave the comfiness of C-like languages.
>>
>>56555173
idk but it's probably talking about the average rate like if you're making requests every half second constantly, but a short burst of a few requests (followed by a pause) is probably fine
>>
>>56555834
I like it when haskellfags talk about how haskell is magically readable when it looks like an explosion in a syntax factory.

>>56555849
>not pump and dump
>>
>>56555285
I presume the "problem" contained within this image is that the person is a female, but I assure you that 90% of all people in intro CS courses are this retarded. I could not believe just how incompetent some of my classmates were at even the most basic of concepts.
>>
>>56555828
>Not remotely true
Otherwise, it's just garbage collection (i.e. you don't have to explicitly call a destructor). Without exceptions or panics, you can call a destructor. With them, you'd have to catch, call a destructor, and then rethrow. Gets hairy with a lot of resources. RAII solves this, but otherwise it's doing minimal work.

>You can create an arbitrary DSL and enforce arbitrary requirements with dependent typing - e.g. "don't refer to this var again"
Well, yes, if you encode a linear type theory in a metatheory then you get linear types. Monads have fuck all to do with that, though.

I get that you're a Haskell evangelist but please learn to accept that there are ivory towers even higher and purer than Haskell has to offer.
>>
>>56555834 >>56555873
What's wrong with it? I get it's different to what you're used to
>>
>>56555894
Maybe I should actually try it, but the syntax looks so awful to me that it discourages me from trying it.
>>
>>56555893
>Otherwise, it's just garbage collection (i.e. you don't have to explicitly call a destructor). Without exceptions or panics, you can call a destructor. With them, you'd have to catch, call a destructor, and then rethrow. Gets hairy with a lot of resources. RAII solves this, but otherwise it's doing minimal work.

This isn't true at all. RAII is mostly just about acquiring resources (doing any necessary tasks), then executing a block depending on them, then freeing them (doing any necessary tasks)

>Well, yes, if you encode a linear type theory in a metatheory then you get linear types. Monads have fuck all to do with that, though.
No, I'm literally saying create an ST-style monad and require that the number of times it's referenced is 1
>>
>>56555849
Purity is an unrealistic ideal that has little to do with reality. Why do you think nobody uses Haskell? All functions are sluts.
>>
>>56555915
>RAII is mostly just about acquiring resources (doing any necessary tasks), then executing a block depending on them, then freeing them (doing any necessary tasks)
Create resource A
Use resource A
Use resource A again
Destroy resource A
That's not RAII. Don't dilute things.

>No, I'm literally saying create an ST-style monad and require that the number of times it's referenced is 1
Sounds like a lot of work when you could just have linear types.
>>
>>56555911
data Console' r = Ask (String -> r) | Say String r

or
template <typename r>
struct Console' {
enum { isAsk, isSay } state;
union {
function<r(String)> ask;
tuple<String, r> say;
}
}


admittedly using the free monad can make the patterns more awkward (you need to use f (Free (...)) but I didn't want to explicitly show writing functor/applicative/monad instances

>>56555936
>That's not RAII
That's RAII
>>
>>56555949
So RAII just means using resources correctly? RAII is common sense?
>>
>>56555924
>are men who live in reality are cucks
Going back to my anime girls and pure functions ;_;
>>
>>56555961
Yeah. It's one of those things academics gave a weird name to so they could inflate their own self-importance and pretend to be part of the industry.
>>
>simplicity of java
>>
Recommend me some Java programming books please.
I've made simple 2d games, but I'm still a novice.

Laptop is dead, got to wait 2 weeks for my desktop parts to arrive.
Need to satisfy my programming urges somehow.
>>
>>56555936
>Sounds like a lot of work to add linear types when you could just have linear types.
Sounds like a lot of work to have linear types when you could just not.


>>56555961
A bunch of these terms get made up and thrown around.
The idea of RAII is that it's automatically done for you, in C++ by the constructor and destructor.

In RAII, holding a resource is a class invariant, and is tied to object lifetime: resource allocation (acquisition) is done during object creation (specifically initialization), by the constructor, while resource deallocation (release) is done during object destruction (specifically finalization), by the destructor. Thus the resource is guaranteed to be held between when initialization finishes and finalization starts (holding the resources is a class invariant), and to be held only when the object is alive. Thus if there are no object leaks, there are no resource leaks.

(Wikipedia)

tl;dnr you just make a class for the resource with a constructor allocating/initialising and a destructor freeing

>>56555990
>Academics
What the fuck am I reading?
This really pisses me off.
It was created by C++ engineers.
That's why it's called "Resource Acquisition Is Initialisation" and is primarily known through constructors and destructors.

Stop blaming everything on the academic boogeyman.
>>
>>56555990
RAII doesn't specifically mean creating resources in a constructor and destroying them in a destructor so that allocating the object on the stack means automatic destruction even if an exception is thrown?

Because I'm pretty sure that's what the term means.
>>
>>56555995
The Scheme Programming Language by Kent Dybvig
>>
>>56555992
>usefulness of haskell
>>
>>56556003
I can't understand your post over all the academic jargon you're using.
>>
>>56555120
what text editor is this?
>>
>>56556003
>Sounds like a lot of work to have linear types when you could just not.
Linear types are rather easy to add to a type theory.

Now, where monads (monadic regions) become useful even if you have linear types is with borrowing, since lifetimes do form a stack.
>>
>>56555995
Effective Go
>>
>>56556037
vim
>>
>>56556037
Editor: Atom
Font: Fira Code
Theme: One Dark
>>
File: 1470431619959.jpg (26KB, 480x270px) Image search: [Google]
1470431619959.jpg
26KB, 480x270px
I know nothing beyond about half of Calc 2 (I've done the Mathematics A-level).

Can someone please explain monads to me, or give me a resource to learn about them, or if necessary point me to where I might learn about the required mathematics before I start with monads?
>>
First for Fuuzetsu.
>>
>>56556179
A monoid in the category of endofunctors, duh!
>>
>>56556044
Linear types cannot provide the benefits of monads

>>56556179
A monad is a generic type that provides "structured value", a function to make a pure function work on a "structured value", a function to turn a regular value into a "structured value", and a function to turn a "doubly-structured value" into a "singly-structured value"
>>
>>56556179
from what we can see, you also didn't learn how to use google
>>
>>56556179
There are no required mathematics unless you want to personally derive the type class from "monoid in the category of endofunctors".

>>56556221
Linear types are better than monads at making computations pure. That was the point from the very beginning.
>>
>>56556236
Probably because literally all the resources are shitty.
>>
>>56556221
Thanks. What's a "structured value"?
>>
>>56556179
>>56556221
>>56556273
It depends on the monad, it's one of the defining features of it.
Note a "structured value" could be anything from a plain value ("no extra structure" being its own kind of structure), to a list of values, to an IO computation that produces a value and performs IO side effects.


For instance, say that you're working with the list monad

Your "structured values" are lists.
The generic type is "list" (you can have a list of any type, it is generic)

Making a pure function work on a list is just mapping the function on the list - i.e. applying the function to each element of the list. (e.g. add 2 to each element of an array)

Turning a regular value into a structured value (for lists) is just returning a single element list. (One consisting just of that element.)

The double-structure to single-structure is just concatenating the list of lists.


>>56556248
>Linear types are better than monads at making computations pure. That was the point from the very beginning.
No it wasn't, someone said "use linear types instead of monads".
There are lots of benefits of monads.
>>
>>56556299
>No it wasn't, someone said "use linear types instead of monads".
Where?
>>
File: 1431389665411.gif (973KB, 256x186px) Image search: [Google]
1431389665411.gif
973KB, 256x186px
>>56556299
>>
>>56556273
>>56556299
And there is another way to define a monad, where rather than a join/flatten operation (double structure to structure) you have a "bind" operation. You can define join in terms of bind and vice versa.

Bind takes a function from a regular value to a structured value, and turns it into a function from a structured value to another structured value
>>
>>56556267
ah. well, in that case, I kinda agree with you.
>>
>>56556308
All I know is we were talking about monads and somebody was like "you should use linear types instead".
But anyway, my point is linear types don't "replace" monads.
>>
>>56556299
>>56556333
Very informative, I understand the list example.

But why couldn't a similar thing be accomplished with a class and methods in another language like C++?
>>
>>56556347
>All I know is we were talking about monads and somebody was like "you should use linear types instead".
Where?

>But anyway, my point is linear types don't "replace" monads.
They don't replace them entirely, they replace them for resource safety.
>>
>>56556386
You can, but it will be ugly.
>>
>>56556299
I don't understand what you're talking about, but it sounds pretty complicated so I'm certain it's bullshit.
>>
>>56555120
I'm writing a program in C++ and eventually I would like to include Python plugin support on it.
Is it better to include it right now, in early development, in late development or in a next version, after everything works properly?
>>
>>56556386
A monad is a particular type constructor and a set of functions.
Doing "the same thing in C++" would still be making a monad.

template <typename T>
using M = Vector<T>;

template <typename T>
M<T> return(T);

template <typename T>
function<M<B>(M<A>)> fmap (function<B(A)>);
// syntax is ugly
// (A -> B) -> (M A -> M B)

template <typename T>
M<T> join (M<M<T>>); // turn a Vector<Vector<_>> into a Vector<_>


>>56556390
>they replace them for resource safety.
99% of monads is not just resource safety
>>
>>56556442
>99% of monads is not just resource safety
And?
>>
File: 1427937673017.jpg (92KB, 290x386px) Image search: [Google]
1427937673017.jpg
92KB, 290x386px
So help me.

I'm making a program that calculates change in python 3x.

I'm using modular to split the amounts and, I guess, categorize them into bills/coins.

Here's what I don't understand:
If I enter 34 cents as my input, I get back 1 quarter, 1 nickel, and 4 pennies which is correct.
But if I enter 94 cents as input, I get back 3 quarters, 1 dime, 1 nickel, and 3 pennies. Where did the last cent go?
>>
>>56556442
A monad is basically just a list, right?
>>
>>56556486
post program, but be careful, your professors can use google, too...
>>
>>56556494
A monad is a spacesuit filled with apples and wrapped in a burrito.
>>
>>56556449
And so by "not entirely" you should mean "not at all".
Linear types can complement monads, but monads lose most purpose in regular do-a-side-effect languages.

Turning effects into a first class construct, as well as including constraining what effects can be done, is the main benefit of monads.
If you look at the OP example, and ignore the top half / the library code (the part defining the monad and the runIO bit), and just look at the bottom half (the user code).

main = runIO greet

"greet" HAS to be of type
Console ()
.
Because it's a pure language, we know the only side effects are Console side effects.
All greet can do is ask for strings and say strings.

Even where the strings come from or where they go is abstracted out of the equation. runIO is one very specific example that runs it using regular console io.

>>56556494
No, a list is one _very_ specific example.
A monad is any (type constructor + set of functions) that satisfies certain laws
There are many very different types of monad.
For instance, if you look at my reply to the other anon in this post, and also look at the bottom half of the OP image.
>>
>>56556549
Okay, what's a type constructor?
>>
File: example.png (22KB, 562x293px) Image search: [Google]
example.png
22KB, 562x293px
>>56556549
I mean this bit of the OP.
>>
>>56556568
In terms of regular languages, think generics or templates. It's something that you give a type and it gives you back a type, e.g. std::vector is a template, it takes a type T and gives you back std::vector<T>, a type.

For example, list is a type constructor.
You could have a list of ints, of bools, etc.
>>
>>56556549
>Linear types can complement monads, but monads lose most purpose in regular do-a-side-effect languages.
I'm not saying that you're ever losing purity. I'm saying that you need monads in Haskell (or any other language without linear types) to do things that linear types do way better.
>>
>>56556442
Thanks, that's a lot of help.
>>
File: Screenshot_2016-09-11_16-26-34.png (127KB, 1280x922px) Image search: [Google]
Screenshot_2016-09-11_16-26-34.png
127KB, 1280x922px
r8 my first hang made program
>>
>>56556594
>C++
>iostreams
Absolute trash.
>>
>>56556578
>You could have a list of ints, of bools, etc.
In sane languages lists may contain any type.
>>
>>56556605
lol
>>
>>56556605
Right, list is a type constructor that takes a type, and gives you back a type.

For instance,
List Bool
List Float
etc

Unless you're talking heterogeneous lists, like a dynamic language or a list of values of polymorphic type
>>
>>56556594
Why do you need a license?
>>
>>56556619
kek

>>56556620
>like a dynamic language
nope
>>
>>56555961
>>56555990
>>56556005
RAII means using a statically allocated object to control data which may fall into an undetermined state throughout a scope's lifetime. For instance, acquiring a lock on a mutex with an RAII object so that if an exception is thrown or the function returns or any other case that the state of a resource becomes undeterminable, the RAII object can cleanup and unlock the mutex.

http://www.sfml-dev.org/documentation/2.4.0/classsf_1_1Lock.php is an example.

It's not some fancy term but a legitimate construct in C++ and I believe Rust.
>>
>>56556638
I don't get what you're trying to say.
My point is, you have a type constructor
List :: Type -> Type
And you use it like so

List Bool :: Type
-- a list of booleans
List Float :: Type
-- a list of floats

etc.
List Bool / List Float are types, List is a type constructor.
>>
>>56556655
>I don't get what you're trying to say.
That sane languages allow values of a list to have multiple types. This is all.
>>
>>56556674
Name one of those languages.
>>
>>56556674
So you DO mean like a dynamic language or a list of polymorphic values?
>>
>>56555285
Just block females from CS courses already.
>>
where does /dpt/ copy its ideas from?
>>
>>56556682
Every sane language.
>>
>>56556701
Name just one.
>>
>>56556682
Java
>>
>>56556689
>like a dynamic language or a list of polymorphic values?
how about neither?
>>
>>56555884
It's an anecdote, but I can attest that even now in 4th year most of my classmates are pretty incompetent. The most competent one happens to be a girl actually.
>>
>>56556710
a language with lists that accept any type? the most popular example is probably python but it's quite shitty.
>>
>>56556714
No, no, no.
If the values don't have one type, then they either have no type, or multiple types.
>>
>>56556711
A list in Java contains objects of the same type. Yes, that type might be Object, but it's one type.

>>56556729
He said not a dynamic language.
>>
>>56555842
>>56555869
Thanks for the input.
Scanning a whole board at once seems like a no-go then.
>>
>>56556745
That's a list of values of polymorphic type

In fact that's textbook OOP polymorphism, the most well known form of all polymorphism
>>
>>56556761
Actually, it's not a polymorphic type. It's a supertype. Subtype polymorphism =/= parametric polymorphism.
>>
>>56556741
dynamic language != no type and "a list of polymorphic values" != "multiple types"

>>56556745
>He said not a dynamic language.
any static lisp then
>>
>>56555173
You really want to risk pissing off a yakuza sysadmin?
>>
>>56556761
>>56556782
Either way, it's still only one type. I don't think you know how types work.
>>
>>56556745
>He said not a dynamic language.
liars deserve AIDS
>>
>>56556560
>The change program is taught in probably every programming class ever, it would take more effort than it's worth for my professor to take a post on 4chan and prove that it was someone in his class.
it's usually done automatically, to check for copied homeworks and stuff

    global amount

    coins = (amount - int_number) * 100

what are you trying to do here?
>>
>>56556782
>it's not a polymorphic type, it's a supertype
It is a polymorphic type, it's of existential type.
I didn't even say parametric polymorphism either.
>>
>>56556782
What do you mean by this?
>>
>>56556560
I tried doing it, and I'm pretty sure it works, but I probably fudged up somewhere (optimization wise):

std::vector<int> returnAmtOfEachCoin(int change, std::vector<int> numOfEachCoin) //Given an amount in cents,
//returns the amount of coins that you'd need to make that amount of cents
{
if(change <= 0)
{
for(int i = 0; i < centsVector.size(); i++)
{
std::cout << "VALUE: " << centsVector[i] << "\tNUMBER OF COINS: " << numOfEachCoin[i] << std::endl;
}
return numOfEachCoin;
}
for(int i = 0; i < centsVector.size(); i++)
{
if(change-centsVector[i] >= 0 )
{
numOfEachCoin[i]++;
returnAmtOfEachCoin(change-centsVector[i], numOfEachCoin);
break;
}
}
return numOfEachCoin;

}
>>
>>56556861
Polymorphic type implies parametric polymorphism. Subtyping is its own beast.
>>
>>56556826
You're right, I deleted the post (not sure if archival sites will save it anyways). I'm pretty confident my professor won't go this hard on checking it, though, it's not a final project or anything.

I actually figured it out.
I printed out the value of coins and boom, instead of '94' it printed out a number like '93.99999997'. No idea why python does that, but to circumvent that, I just took the user input and *100 it to make it an integer.

This seems to have fixed that.
>>
>>56556884
I mean exactly what I say.
>>
How do I make sure a number is even in java? I remem it being something like

(value)%2

Help
>>
>>56556897
>Polymorphic type implies parametric polymorphism
I didn't mean parametric polymorphism, and subtyping is a kind of polymorphism, like it or not.
>>
File: 705_devotion_to_duty.png (34KB, 638x247px) Image search: [Google]
705_devotion_to_duty.png
34KB, 638x247px
>>56556791
probably not
>>
>>56556936
Okay, but Object is not a polymorphic type. It is just a type.
>>
>>56556954
Values of object can have more than one type, and if it's an abstract base, then they do have more then one type
>>
>>56556908
for me, the code you posted worked simply by removing the multiplication
coins = amount

instead of
coins = (amount - int_number) * 100

you probably got confused at some point
>>
>>56556929
You're close
What would an even number return and what would an odd return?
>>
>>56556965
That's got nothing to do with Object being a polymorphic type.

This is an example of a polymorphic type:
∀A.A → A
>>
>>56556966
Actually the original code I posted had an interesting issue
If you entered just 94 cents, as in '0.94', it prints out the correct amount of pennies.

However if you print out a larger number like '175.94' you would lose a penny.
>>
>>56556968
An even would return a whole number(2/2=1 for example)

An odd would return a decimal number(3/2=1.5 for example)

The odd would also leaving 1 number out

Example:

3/2
3-2/2(1)
1/2(1)
10/2(1. )
10-10/2(1.5)
0
>>
>>56556980
>That's got nothing to do with Object being a polymorphic type
If all the values of a type have multiple types, I think it's fair to call it a polymorphic type. The implication isn't that the type itself is polymorphic
>>
>>56557027
No, that means it's a subtype.
>>
>>56556951
>tfw want to be sysadmin
>have no idea where to begin
>/dpt/ calls me a script kiddie if I ask for books/authors/links to where to even start
>>
>>56557037
Subtyping is a type of polymorphism
>>
>>56557062
The term "polymorphic type" is specific to parametric polymorphism.
>>
>>56557025
Compare 3 % 2 and 2 % 2
>>
>>56557062
He's basically just taking issue with saying "values of polymorphic type" over "polymorphic values", because in the regular sense only the values are polymorphic and not the type
>>
>>56556760
It'd be fine if you grab hold of the entire board's information at once and then search through the hash (or whatever) afterwards. Keep the actual requests down to a minimum.

The Racket interface to the 4chan API can grab the information for an entire board at once (via the catalog). I don't know what language you're using, but there should be something similar available.
>>
>>56557038
https://www.freebsd.org/doc/en/books/handbook/
>>
>>56557077
ah I see, only skimmed the last few posts
>>
>>56557106
Basically, someone claimed that subtyping means you have heterogeneous lists and the debate went off from there.
>>
>>56557130
Subtyping lets you have a list of values of multiple types (the subtypes)
>>
>>56557094
I'm trying to examine every post and count specific keywords so when I sad "Scanning a whole board" I meant get catalog infos and then scan every of the 150 or so threads.
Therefore I have 151 requests per cycle.
Meaning scanning the "whole" board every 2.5 minutes which doesn't sound too bad but meh.
Maybe I need a priority system to be able to update the more active threads more frequently or something.
>>
Absolute noob here, pls bully gently

Where do I put custom headers? Running linux and using geany
>>
>>56557157
No, the list is of values of all one type. If A <: B you can turn a value of type A into a value of type B but the opposite operation (downcasting) is unsound.
>>
I'm messing up, and am trying to cast a pointer. The pointer points to what (I think) is just a single char that I want to be an int. I'm doing this by passing arguments to main

int main(int argc, char *argv[])
{
*++argv;
int a = *argv - '0';
printf("%d\n", a);
}


And I compile like so:
gcc program.c
./a.out 4


I would expect this to print 4, but it is a compiler error because I don't know how to cast the pointer. Changing the program to:
int main(int argc, char *argv[])
{
printf("%s\n", *++argv);
}

Does print 4. So I'm assuming argv at that index points to '4' '\0'. How do I get that single character '4' and change it to an int?
>>
>>56557182
>didn't mention what header I actually meant
by "header" I meant stuff like this:
http://www.stroustrup.com/Programming/std_lib_facilities.h

so I just put it in my project or can I put it somewhere so my IDE has it always?
>>
>>56557184
>The list of values is all of one type
Your values can have multiple types.
That's the whole point of subtyping.

a dog has the types dog, mammal, animal, etc
>>
>>56557212
no, at the point in time when they're inserted into the list, the values have one type
if your language has dynamic typing, you can extract them and then coerce them to the type from before they were inserted into the list
>>
>>56557184
In practice, though, because usually subtyping is implemented with vtables and references you don't actually lose information from subtyping and can downcast as long as you get the derived type right. Doesn't make it any less unsound in general. For instance, it breaks LSP, which is basically the only reason subtyping is useful other than to emulate unions.

>>56557212
All the values in a list of animals have type animal.
>>
>>56556486
Is "34 cents" represented in your code as 0.34 (a float or double, don't know Python) or 34 (an integer)?

If you're representing it as a float/double, try representing it as an integer.
>>
>>56557082
So like this

x = 3;
y = 2;
a = x%y;
if(a>=1){
System.out.println(x + " is an odd number")
}
>>
>>56557222
>>56557225
Yes, they all have the type animal.
And some of them have extra types too, that's how subtyping works.
>>
>>56557242
compare with zero because with negative odd numbers you get -1

https://en.wikipedia.org/wiki/Modulo_operation#Common_pitfalls
>>
>>56557194
i don't even know where to start....
>>
>>56557248
No, they don't. Unless animal has a supertype, but it's still a homogeneous list.
>>
>>56557270
Thanks mate
>>
>>56557278
x : dog
dog <: animal
therefore x : animal
>>
>>56557297
That has nothing to do with what you are claiming.
>>
>>56557311
x has type dog
x has type animal

x has two types
>>
>>56557320
That has nothing to do with what you are claiming.
>...sane languages allow values of a list to have multiple types. This is all.
Unless you really meant that e.g. you had a list of A where A <: B, which isn't notable.
>>
>>56557346
I'm not him
Any given value B where A <: B may have more than one type
>>
>>56557368
and virtual dispatch is pattern matching on those unknown additional types
>>
>>56557368
Downcasting is not logically sound. It exists because of how subtyping is typically implemented in OO languages.

There's no way to say that A <: B, x : B therefore x : A without having x : A before coercing it to a B.
>>
>>56557420
>There's no way to say that A <: B, x : B therefore x : A without having x : A before coercing it to a B.
I'm not saying that

I'm saying, given that A <: B, and that x : B, it is possible that x : A
That's what I mean by >>56557401
>>
>>56557430
Nobody's disputing that. You've simply jumped in a discussion without making it clear that you're a different person not arguing for the same point.
>>
>>56557430
>>56557452
And yes, while it is possible, it is not provable without other information. And you wouldn't be using either of those assumptions in the proof.
>>
>>56557481
>And yes, while it is possible, it is not provable without other information. And you wouldn't be using either of those assumptions in the proof.

My point is that if you've got a list of values of multiple subtypes, you've got a list of values of multiple types.
>>
How can I make it so the user creates a variable? Programmin in java btw
>>
>>56557544
>if you've got a list of values of multiple subtypes, you've got a list of values of multiple types.
>if you have a heterogeneous list you have a heterogeneous list
Can't argue with that logic.
>>
>>56557570
A list of values of a base type IS a list of values of multiple non-strict subtypes
>>
>>56557565
What do you want exactly? Have you considered creating a new value in a list maybe?
>>
File: coolpka.jpg (9KB, 175x211px) Image search: [Google]
coolpka.jpg
9KB, 175x211px
>>56557274
Stumped you weenies again.
>>
>>56557583
No, it's not.
>>
>>56557601
Yes, it is. That's how subtyping works.
>>
>>56557585
Nvm just found a workaround
>>
>>56557613
>>56557601
You could think of the base type as a set of its subtypes.
(Ignoring heirarchies.)

So since Animal = Cat | Dog, [Animal] = [Cat | Dog]
>>
>>56557613
A <: B

f : B -> B
f = id

a : A
b = f a : B

Can you conclude that b : A?

>>56557670
That's not subtyping.
>>
>>56557194
At least I don't know what you mean with the asterisk in the line
*++argv
. It won't change the pointer from a char** to a char*, you need a new variable for that.

int main(int argc, char *argv[])
{
++argv;
int a = **argv - '0';
printf("%d\n", a);
}


But I think that the code can be much more readable if you actually use array index instead of references. I assume you're trying to get some concept of pointers, so better keep that way.
>>
>>56557685
>Can you conclude that b : A
Not from the types you gave it, the type of f would have to indicate that it preserves subtypes (or that it produces an A from at least an A)


And that is the textbook definition of subtyping.
>>
>>56556594
kek'd
>>
File: 1471574597768.png (9KB, 904x542px) Image search: [Google]
1471574597768.png
9KB, 904x542px
>>56555285
>You will never lodge your penis betwixt Alison Rapp's thicc legs
Why live lads?
>>
>>56556916
what did he mean by this?
>>
>>56557721
>Not from the types you gave it, the type of f would have to indicate that it preserves subtypes (or that it produces an A from at least an A)
So how can you say that a list of B contains a value of A? b is a value of A in my example by that same logic.
>>
When using fgetc() in C on files containing non-ascii values. Will it return values in the 128+ range correctly?
>>
>>56557744
How thick we talking?
>>
>>56557721
>>56557749
My point is, once you put a value of A into a list of B, it ceases to be a value of A.
>>
Made a nice program which downloads every image for a given tag on rule34.paheal, it's a tad slow because of the rate limiting, I have never done anything to do with networks or downloading before so this is probably a stupid question, but does the rate limiting apply to just downloading index pages or does it apply to downloading images as well?

I imaged it applied to everything on the server so I currently am delaying a second between requests which makes it take a while for 7000 images.

Very happy with my program, works well and didn't have too many bugs to fix, it's only 200 lines along with a lot of comments

feelsgoodman
>>
>>56557749
>So how can you say the list of B contains a value of A?
You can't, I didn't say you could.
You could obviously say that the list of B might contain a value of A.
>>
>>56557785
See >>56557765
>>
Can someone send me the link to akari? I somehow lost it
>>
>>56557768
also should I upload this to github? I don't know if people I send my github to would be bothered it they knew what it was for
>>
>>56557785
And as I was saying, if you indicated that id preserves subtypes, then you could infer that.

>>56557794
You literally just restated your claim.
And you didn't even read my post.
>>
>>56557813
It might contain a value of B that came from a value of A but that doesn't mean shit.
>>
File: 1471397567615.jpg (19KB, 343x354px) Image search: [Google]
1471397567615.jpg
19KB, 343x354px
How do I handle dependencies for multiple platforms with C programs? Like if I write a portable C program with portable dependencies, what is the best way to distribute the source in a way that is simple to build on all platforms?

The approach I was thinking of was looking into git submodules for dependencies and then using a build system like cmake. Is there a better method/system than that? Should I not do that? I've heard people say not to use submodules and that cmake is a mess but I never got any reasons, examples, or alternatives.
>>
>>56557765
>>56557794
And the claim's obviously false

Just because you put a Dog into a list of Animals doesn't mean it stops being a Dog, it just means that you don't know that it's a Dog

>>56557835
I've got a set of specific even numbers { 0, 2, 8, 10 }
I put in the number 4

{ 0, 2, 4, 8, 10 }

I take out the even number 4 that is definitely not a 4 that doesn't mean shit
>>
>video game tattoos
ugh i guess

>>56557755
medium thicc
>>
>>56557849
>Just because you put a Dog into a list of Animals doesn't mean it stops being a Dog, it just means that you don't know that it's a Dog
No, it stops being a dog. It might retain properties of the dog object through e.g. a vtable, but strictly speaking it does not have any type other than animal (although it could be coerced again to e.g. organism).

>I take out the even number 4 that is definitely not a 4 that doesn't mean shit
???
>>
>>56557915
>No, it stops being a dog.
No it doesn't.

>???
Exactly.
>>
>>56555120
just finished, thoughts?
>>
>>56557932
If it has type animal and barks like a dog, it has type animal.
>>
>>56555120
6502 assembler
>>
>>56557979
No, it has type dog and type animal (& it can't ONLY have type dog).
When you then cast it to an animal you lose the knowledge that it's a dog, it doesn't stop being a dog.
In your earlier example, you could hypothetically annotate f with the information that subtypes are preserved, and then you could infer the specific subtype of f a
>>
>>56558012
You may be confusing this because of references. In e.g. Java, you don't actually ever have an object itself, you have a reference to an object. You can turn a dog reference to an animal reference, but it still refers to a dog, just through the animal lens. This does not mean it is a dog reference.
>>
>>56558012
Another example of this is covariant return types
A lot of languages let you override
Animal foo();
with
Dog foo();

>>56558047
>You may be confusing this because of references
What? I don't use Java and have never mentioned references
>>
>>56558055
>Another example of this is covariant return types
>A lot of languages let you override
>Animal foo();
>with
>Dog foo();
That's because virtual methods are just first class functions. If A <: B, then C -> A <: C -> B. You're not wrong, but that has nothing to do with this.

>What? I don't use Java and have never mentioned references
I didn't say you did, I'm suggesting where the confusion might be coming from, and Java was the first example of a language that came to mind. If you coerce an A to a B where A <: B, that new value of B isn't a value of A. You might still have that value of A somewhere (even inside the value of B), but that's beside the point because that's not what you're asserting.
>>
>>56558118
A dog is a dog, even if it is also an animal
>>
I'm amazed we got this far without you guys throwing a single insult
>>
>>56558150
A civil person is still a civil person

even if they are also an idiot :^)
>>
>>56555281
>Java
>Stack allocation
>>
>>56558134
True, but you still aren't understanding that a value of B is just a value of B. Coercing a value of A to a value of B makes a new value. That new value is not a value of A. It might contain a value of A, but that is different.
>>
File: Touhou Project - Friends Now.jpg (57KB, 529x386px) Image search: [Google]
Touhou Project - Friends Now.jpg
57KB, 529x386px
>>56557846
>what is the best way to distribute the source in a way that is simple to build on all platforms?
That actually changes from project to project and the real answer is try different things and find what you think is easiest to actually deploy. My personal take is that the source code itself can be distributed as-is, but with a notice saying these external libraries are dependencies and it's the builder's responsibility to ensure they're installed properly.

As for git submodules, please do not do this. If you're trying to make an ebuild for Gentoo, there is a way to use git submodules, but the proper way is to have separate ebuilds for each library. It's nice to have them separate because if another project starts to use a library/code that's included in one of the aforementioned hypothetical submodules, then they can reuse that already installed library instead. I suppose the same could be applied to deb and rpm, but I have no real experience creating packages in those formats.
>>
>>56558186
You're thinking with a language in mind.

You don't "coerce" an A to a B when A <: B.
An A is already a B.
>>
>>56558195
Thanks, I'll do some experimenting sending it to people on various platforms and leave build notes.
>>
What's a good way to help learn Java? When I'm home I only have access to internet by my phone and I don't have unlimited data. But, I'm in my first programming class and I'm a bit overwhelmed bc I'm struggling with some programs we have to make.
>>
>>56558251
Whatever resources you use normally just download them and view on your phone, html, text, pdfs, videos, etc.

Packrat that shit so you don't need to use your data.
>>
File: 1472516292639.png (566KB, 1000x352px) Image search: [Google]
1472516292639.png
566KB, 1000x352px
>>
>>56558267
When I'm at my uni I have access and I can drive to a coffee shop. Is code academy good for actually learning the language or is it just situational stuff that won't really teach me it?
>>
>>56558208
I was thinking with type theory in mind, but you're right in that coercion is just an inference rule and not something that is specifically invoked.

Let me get this straight: what you're saying is that a : A, A <: B so a : B. You then conclude that if you have x : B you could also have x : A. I suppose you're not wrong.
>>
>>56558276
Is that the shitty logic that gave us ++x and x++?

Where post-increment increments previously and pre-increment increments in post?
>>
>>56558251
Get it straight from the source.
http://www.oracle.com/technetwork/java/javase/java-tutorial-downloads-2005894.html
>>
Waiting for "project managers" to come online so I have something to do...

Full stack c#/.net web dev.
>>
File: Screenshot_2016-09-11_20-46-40.png (436KB, 861x528px) Image search: [Google]
Screenshot_2016-09-11_20-46-40.png
436KB, 861x528px
Started working on moving my VM from Cython to D, it's nice because I get a chance to rethink some things
>>
>>56555285

>See Bubble Sort algorithm
>OMG MATH!

Bitch, just go work at McDonalds.
>>
>>56557882

Atrocious tattoos.
>>
>>56558394
>See monads
>OMG MATH!

Bitch, just go work at McDonalds.
>>
>>56558394
>!Sempai.oWA
>>56558425
>!!Ju67JuF6jBe
filtered
>>
>>56558445
How new are you? They've been in these threads for ages and you're just now filtering them?
>>
>>56558440

Type/Category Theory an obscure branch of math not touched upon in most computer science curriculums, and not touched upon in any math curriculum I've ever heard of. The problem isn't so much that it's math, as much as it is that only Haskell programmers know what the fuck it is.
>>
File: 1.jpg (144KB, 1080x1080px) Image search: [Google]
1.jpg
144KB, 1080x1080px
coderlife
>>
>>56558477

bind, return, monad laws. e-z p-z.
>>
>>56557846
Don't use submodules, it's up to the person building to obtain their dependencies.

Use cmake, don't listen to others because there's literally no alternative better than cmake (I don't even know if there are alternatives). Most of the libraries I've had to build myself used cmake and they're widely used libraries used libraries (OpenCV is one). If cmake truly was garbage they wouldn't use it.
>>
now that the dust has settled

http://www.strawpoll.me/11207512
>>
>>56558477
You only need to know category theory if you want to derive this:
class (Functor m) => Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b

return a >>= f = f a
ma >>= return = ma
(ma >>= f) >>= g = ma >>= (\a -> f a >>= g)

From this:
>a monad is a monoid in the category of endofunctors
>>
>>56558477
>>56558509
this uses monads
>>56556570
>>
>>56558537

Yes, I/O is monadic.
>>
How do I make my read and write methods not conflict with those defined in unistd.h?
>>
>>56558522
CMake is the standard "better" system, but SCons is the best.
>>
What is the best way to get the new posts from a forum in python without spamming it with requests?
>>
>>56558553
No, "runIO" just runs the example with IO.
The actual example is a very restricted monad that simply defines the ability to put a string in (say) and take a string out (ask).
"greet" couldn't, for instance, wipe your hard drive, while IO could


>>56558528
it's really not that bad
a monoid:
(+) :: M x M ~> M
0 :: I ~> M


let X = functor composition
let I = the haskell identity functor
data Identity a = Id a


(+) :: M (M a) -> M a
0 :: I a -> M a

I a is isomorphic to a, rename

join :: M (M a) -> M a
return :: a -> M a


It's a shame we don't have more general definitions
>>
>>56558575
And the monad doesn't need to be run in console, it's a completely abstract specification for putting strings in, taking them out, and performing pure computations on them.
You could run it with a fixed set of inputs.
You could use it as a kind of server exchange language
>>
>>56558575
Oh, and as for the monoid bit, the haskell monoid:

let x = (,)
let I = ()
(product and empty product)

(+) :: (M,M) -> M
0 :: () -> M


((a,b) -> c) is isomorphic to (a -> b -> c)
(() -> a) is isomorphic to a
curry (+), remove ()
(+) :: m -> m -> m
0 :: m
>>
What does /dpt/ think of Rust?
>>
>>56558642
it's not the worst language but imo it's pointless because it's like a shittier and less popular C++
>>
>>56558642
Lots of potential.

>>56558660
>shittier C++
No.
>>
>>56558668
if it wasn't shittier it wouldn't have """"lots of potential"""" to be good, it would already be good
>>
>>56558509

Meh. Procedural and OOP styles do pretty much all I need.
>>
>>56558555
in case anyone cares, this did the trick
>>
>>56558707
you can do procedural code in the IO monad
>>
>>56558377
I'm confused. The compiler error is referencing a function that returns void, while the code shows the function returning vector<char>. However, the functions have the exact same arguments.

Also, consider not using
using namespace std;
>>
>>56558572
Someone plss..
>>
>>56558686
It's already better than C++ but it has potential to be even better.
>>
File: 1468472224634.jpg (61KB, 990x557px) Image search: [Google]
1468472224634.jpg
61KB, 990x557px
>>56558440
>muh monads
>>
>>56558730
Quoted the wrong post. Sorry mate.

Should point to >>56558555
>>
>>56558707
>Graham considers a hypothetical Blub programmer. When the programmer looks down the "power continuum", he considers the lower languages to be less powerful because they miss some feature that a Blub programmer is used to. But when he looks up, he fails to realise that he is looking up: he merely sees "weird languages" with unnecessary features and assumes they are equivalent in power, but with "other hairy stuff thrown in as well".
>>
File: anime.png (201KB, 335x365px) Image search: [Google]
anime.png
201KB, 335x365px
>>56558740
No, MY monads
>>
>>56558719

You can, but it's easier to reason about procedural code in languages designed for procedural code.
>>
>>56558755
You'd be surprised
>>
>>56558752
haskell and such languages are useless for most programmers, you wouldn't make a serious AAA game or something in fucking haskell
>>
>>56558755
Haskell is designed for procedural code to be written in a way that makes it easier to reason about.
>>
What's a good language to learn if I like C, but want something with a larger standard library when I'm not doing embedded stuff?
C#? SEPPLES?
>>
>>56558775
you wouldn't make a serious AAA game in anything other than a very strict few languages

not the engine, at least
>>
>>56558775
>monads apply to Haskell and Haskell only
>>
>>56558730
You're correct in that I had errors in the code I originally showed, but even after fixing them I ended up with the same compiler error. See >>56558709 for the fix.

>> Also, consider not using using namespace std;

I'm not. I have
 
template <typename T>
using vector = std::vector<T>;

for some of the STL things I use frequently, which I understand to be acceptable.
>>
>>56558791
>and such languages
>>
>>56558798
Like?
>>
>>56558794
My mistake for assuming.
>>
>>56557194
argv is a list, you cannot use pointer arithmetic on it. Just use
 printf("%s\n", argv[1]); 
to print the second command line param
>>
>>56558880
>argv is a list
It's an array of char pointers.
>you cannot use pointer arithmetic on it
Sure you can.
>>
How do I even get started writing javascript? I've been learning C/C++, Python and Java for years but since javascript is a web language, do I have to open up an html file in my browser every time I want to run it?
>>
>>56557194
Also please read The C Programming Language. Even just the chapters on pointers and arrays will help a ton.
>>
>>56558752

In Haskell, you use monads to explain procedural code in terms of functional programming.

In C and C++, you explain higher level concepts as mere syntactic sugar for procedural code. A function is merely a procedure that does not have "void" for a return type. A struct is merely a way of organizing data that is related, into a single type. Object oriented programming expands upon the struct by combining data and "methods" together to create a type that describes a self-contained state machine, known as an object. Ultimately, however, this type is still a struct at heart, and uses the compiler to allow for things like data hiding and polymorphism. Languages like Java and Ruby, which are designed around object oriented programming, may use the runtime to better enforce the model, but in the end, everything boils down to a procedural base. Every abstraction in every language comes down to procedural assembly in the end.
>>
>>56558922
Abstraction isn't necessarily good for reasoning. And those languages do almost nothing about shared mutable state, which throws most reasoning out the window.
>>
Hey anons, do you know a host service to let me run a python script that use socket? i tried in https://www.pythonanywhere.com/ but they don't let me send packets
>>
>>56558899
>It's an array of char pointers
Same thing
>you cannot use pointer arithmetic on it
int main(void)
{
char* hw[3] = { "Hello ", "world", '\0'};
printf("%s\n", ++hw);
return 0;
}

You can't use pointer arithmetic on array items.
You could use arithmetic on each pointer in the array but it makes no sense in the example
>>
>>56558963
>those languages do almost nothing about shared mutable state
>it's this delusional fedora tipper again
yes they do
>>
>>56558977
You're misunderstanding btw
>>
>>56558977
>Same thing
Not at all.
>You can't use pointer arithmetic on array items.
You can't modify an array label, which is what your code is trying to do.
hw + 1 works fine, although is the wrong type of argument for printf.
Arrays as function arguments (i.e. pointers) are modifiable though.
>>
>>56558922
Procedural code in appropriate monads is most assuredly procedural.

C-like languages have a million inconsistencies and C++ especially has a lot of things that make it even harder to reason about code.
>>
When I type:

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;


I might as well type:

import java.awt


And that would import everything in java.awt right? That would import the ones I mentioned plus another bunch of things I don't need right? Or do I need to type anything special to make it work like that?
>>
>>56559048
import java.awt.*;
>>
New thread: >>56559070
>>
>>56559048
 import java.awt.* 

And yes, i would import everything in the java.awt namespace.
>>
new
>>56559084
>>
>>56558997
> hw + 1
What does adding to an array do? I've never seen it done..
>>
>>56559102
It points to the element at index 1, and is exactly equivalent to
&hw[1]
>>
>>56559119
Is it just an uncommon syntax?
I guess it makes sense tho
#include <stdio.h>

int main(void)
{
char* hw[3] = { "Hello ", "world"};
printf("%s\n", *(hw + 0));
return 0;
}
>>
>>56559102

Adding to a pointer just increments the memory address it points to.

char array[3] = { 'a', 'b', 'c' }
&array[0] // pointer to 'a'
&array[1] // pointer to 'b'
&array[0] + 1 // also pointer to 'b'
&array[0] + 2 // points to 'c'
>>
>>56559145
It's called pointer arithmetic. It sees a lot of use in C, and the [] operator is just syntactic sugar for it.
>>
>>56558555
Use namespaces, as C++ expects you to do.
>>
>>56559155
What about hw + 1. I know what hw[0] + 1 would do.
>>
>>56558963

>Shared mutable state
As I see it, it is entirely up to the programmer how much they want to fuck their own shit up with globals. If something doesn't need to be accessed by pretty half of the procedures in your code or accessed by multiple threads, you should probably just pass it around as a parameter, perhaps by reference if it needs to be mutated by another function. Regardless though, it's not too difficult to reason about.

>>56558998

C's inconsistencies aren't THAT numerous, and pretty much all of C++ is syntactic sugar and RAII.
>>
>>56558922
The problem, though, is that your typical imperative language blesses one particular composition of rich monadic structure and bakes it into the semantics of all procedures. All procedures can query a shared context. All procedures are able to throw exceptions instead of producing values. All procedures can mutate state unrestricted. All procedures may be nondeterministic in their behavior.

These are obviously useful things, and Haskell provides such rich do-everything imperative procedures with IO. And IO procedures in Haskell are just as intractible to reason about as in any other procedural language. But they aren't blessed. In other words, they aren't second-class. IO procedures are first class values. You can compose them however you want, making your own control structures out of functions on procedures.

You are also free to use other compositions of monadic structure. The STM monad for example encodes procedures that are able to mutate variables transactionally, without any of that other side-effecting nonsense. This allows their implementation to be smart: if two threads try to clobber the same variable, the implementation might give them both a different view of the world and reconcile the differences when they try to commit, or one could restart its transaction without worrying about other side effects.
>>
>>56559196
 &a[0]+1 
and
 a[0] + 1 
are different operations. The former adds to a pointer to an element while the latter adds to the element itself.

 
char a[3] = { 'a', 'b', 'c' };
a + 1 == &a[0] + 1 // maybe?


I think that snippet is true, but I'm not sure. There is a subtle difference between a pointer and an array name that I don't understand well enough to speak about definitively.
>>
>>56559196
Array index is a mixfix pointer arithmetic operator. This is its definition:
a[i] == *(a + i)

So it follows that:
&a[i] == &*(a + i) == a + i
>>
>>56559196

hw + 1 is &(hw[1]).
hw[0] + 1 is (*hw) + 1.

If you have an array foo, the name foo decays to a pointer to the first element in the array.

>>56559233

>The problem, though, is that your typical imperative language blesses one particular composition of rich monadic structure and bakes it into the semantics of all procedures

As I see it, the problem with Haskell is that it doesn't do this. A procedural style is the lowest level of abstraction, because it is the style used in assembly language. Therefore, further levels of abstraction are syntactic sugar -- a convenience over procedural programming that still boils down to procedural code in the end. As I see it, most of functional programming is simply using a subset of procedural programming to avoid the use of mutable state (which is perfectly fine -- it can really help reduce bugs in some circumstances). Meanwhile you see procedural programming as a special case of functional programming, which is somewhat irrational. When you peel off all of the layers of abstraction in the Haskell stack, you are still generating procedural code. A programming language is merely a tool to generate assembly without actually writing assembly.
>>
>>56559378
Totally agree with you man, those crazy Fortranners aren't even doing programming. Real programmers write assembly directly.

I mean how could anyone possibly write good programs if you have to give up so much control over your code to the whims of a compiler?
>>
>>56559419

I think you missed the point. My point is that no matter what language you are writing in, the computer is going to interpret it as assembly. From a procedural programmer's perspective, every high level language construct has a one to one mapping to some amount of lines of assembly code, which is procedural in nature. Therefore, all code is merely syntactic sugar for procedural code. Functions are merely a subset of procedures. Trying to explain procedures in terms of functions and types is therefore pointless.

I'm not saying abstraction is wrong (although I certainly find some kinds of abstraction to be harder to reason about), merely that we should not confuse the ground for the sky.
>>
>>56559545
I got your point. Classic case of Stockholm syndrome. Tragic, really
>>
>>56559572

>He has a point
>He must therefore have Stockholm Syndrome!

A note about Stockholm Syndrome: you generally have to suffer first to get it. I never really disliked programming in C to begin with. It's just easier to think about.
>>
>>56556179
The programming variety I assume?

Monads allow you to compose functions, while adding in extra functionality or information.

Do you know promises JS? Monads!
You compose functions, with the additional context of being async.


If you're interested in them in a more traditional category theory/math context, check out Conceptual Mathematics: A First Introduction to Categories.
It's written targeted at a high school level so you should be fine to just dive right in.
>>
>>56558561
What makes SCons better than CMake?
>>
>>56557957
>stop all
I wish
Thread posts: 332
Thread images: 26


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.