/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1557279904231.jpg (900x882, 217K)

nth for Nim!

Second for Rust is a functional language.

Having filter and map doesn't make a language functional.

Right back at you, lad. Fuck you and your weeb autism.

>If people call Lisp and OCaml FP, then Rust is surely FP as well.
People call Javascript FP too.

Where do you think you are?

Attached: 1541283524897.jpg (933x1200, 159K)

If a languages has functions it's a functional language

In Jow Forums, not /a/.

Attached: 1422487821007.jpg (800x800, 273K)

Functional as in working or functional as in the paradigm?

I have, Rust is nothing like Lisp, it's more FP. Lisp's claim to be a FP language is as valid as PHP7's - both have closures and first-class functions.
Still, it's not actual HKT, tho it's close enough.
> Who actually uses RHEL?
People with a job? Like, the definition of being "practical".

Neither.

>Rust is nothing like Lisp, it's more FP

Attached: 3b6.jpg (353x400, 20K)

cute OP
if I don't finish this part of using libcurl in my program today I'm killing myself

How do I Swing with Java?

Lisp is not even based on the Lambda Calculus, tho it looks like the Untyped Lambda Calculus - the most primitive one from the 1940s.
Rust is based on OCaml and Haskell, which are built on Typed Lambda Calculus and System F.

Cute bong

Don't respond

turn 3 240 360 and poo in it

Samefag

No, there's no "actual" about it. HKTs are simply determined - can you pass type constructors as arguments to functions and type constructors? The answer is definitively yes.

>What are you working on, Jow Forums?
writing a functional programming language,
it's like Cbut with map and filter.

and were both me, yes, but the rest aren't.

1.0 RC literally any day now.

techloli/g/y

>autist is throwing a tantrum again

Yes, you're in Jow Forums, the board who's board letter stands for 技術, the Japanese word for technology. And before that, it stood for グロ, the Japanese word for grotesque.

And before that, it stood for "get a load of this faggot".

>Retarded anti-anime autist complaining about anime on an anime website
Just make sure to include cute anime pictures with your posts.

>What are you working on, Jow Forums?
I'm continuing to make changes to my wayland compositor. I've got to try and keep my changes to a minimum so it's easier to merge, but everything I do always ends up spiralling into multiple 1000s of lines changes in the PR.

Attached: 1525102272864.jpg (750x1000, 125K)

Yeah, but C++ templates aren't type constructors. They look like ones, but not really are.

>C++ templates aren't type constructors
template
using Foo = Bar;

If you have a job it's functional autism.

#define PAIR(T) struct { T first; T second; }

Is the a type constructor too?

Sure why not.
It's shit though because it's just a textual macro, whereas isn't.

Nope, it's not a first class symbol and cannot be manipulated as one.

I'm working on a project in my cagie right now.
At home, I'll learn Rust via solving some assignments in Rust instead of sepples since I'm too much of a brainlet for it.

What is a type constructor other than a function over types?

I'm working with sqlite in C where 3 variables in the code will be saved to a database. Would this code work assuming all variables are int? I haven't compiled yet as I am just writing this in text.
char *sql = "INSERT INTO machinestate(pc, ac, ir VALUES(?, ?, ?);";
rc = sqlite3_prepare_v2(db, sql, strelen(sql) + 1, &stmt, NULL);
if (rc != SQLITE_OK)
{
printf("ERROR: %s\n", sqlite3_errstr(rc));
sqlite3_close(db);
return 1;
}

rc = sqlite3_bind_int(stmt, 1, m->pc);
if (rc != SQLITE_OK) {
printf("ERROR: %s\n", sqlite3_errstr(rc));
sqlite3_close(db);
return 1;
}
rc = sqlite3_bind_int(stmt, 2, m->ac);
if (rc != SQLITE_OK) {
printf("ERROR: %s\n", sqlite3_errstr(rc));
sqlite3_close(db);
return 1;
}
rc = sqlite3_bind_int(stmt, 3, m->ir);
if (rc != SQLITE_OK) {
printf("ERROR: %s\n", sqlite3_errstr(rc));
sqlite3_close(db);
return 1;
}
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
printf("ERROR: %s\n", sqlite3_errstr(rc));
sqlite3_close(db);
return 1;
}

> Sure why not.
Because it's not a part of the type system, it's a textual macro, just like templates. Granted they are very advanced textual macros with ad-hoc support from the language.
Non-instanced templates are not first-class symbols too, you can't export them from a library, for example, you have to have the source code available for textual substitution.
Good question, I'm not sure where to draw the line myself, to be honest. As I see it, C++ templates have nothing to do with type theory and grew out of textual macros (you can read about it in Design and Evolution of C++), while languages like Haskell, C# and Rust have generics based on sound type theory like System F, where the term "type constructor" comes from. It's a case of convergent evolution, but that doesn't make C++ templates type constructors, just like dolphins aren't fishes.

Attached: hqdefault.jpg (480x360, 26K)

>it's a textual macro, just like templates
Wrong.
>it's not a part of the type system
Yeah macros aren't but templates are.
Learn C++.

>you can't export them from a library, for example, you have to have the source code available for textual substitution.
Modules would like a word with you.

Can you typecheck or export a non-instanced template? You can't, therefore it's not a first-class entity but merely a textual template with holes to fill in. In languages like Haskell, C# and Rust all the generic code is typechecked, pre-compiled and can be exported from an assembly/crate.

>tfw typing "quicksort" into Google for the fifth time.
Assuming I'm not a brainlet, which is a big assumption I realize, is it normal to need to look up an algorithm every time I need it?

Attached: 1543886911327.jpg (500x352, 48K)

>Can you typecheck
Yes in C++20
>or export
Yes in C++20

Come back in a year and we'll see, then.

Sure. It's good to know of a lot of algorithms, so you can easily pull them out when you need them, but there is no point trying to restrict yourself into not looking them up. Most algorithms have shitloads of little details that would be easy to forget.

constructor would sort of imply matchability (which a general lambda doesn't necessarily have)
i.e. f = g iff f = g and a = b
it's still HKTs though

In that case, types don't exist in C or C++ either because the definition of them needs to be present "textually" before they can be used.

>it's a textural macro
>just like templates
I'd love to be able to bait C++ programmers with posts like this someday.

C++ does actually support matching and destructuring types built from class templates but not general type lambdas.

No? Types are part of the type system, they are used for type checking, there's nothing wrong with types. To be clear, there's nothing wrong with templates too, you just have to realize the way they work is basically equivalent to C macros, thus duck typing.

no you can do
template
using Fun = ...

plus you can pattern match by specialisation

When you say it like that it sounds like you're re-implementing quicksort every time you use it.
It's not a bad thing to explore an old design but I doubt you'd productively reinvent quicksort.

>you just have to realize the way they work is basically equivalent to C macros
No, not at all.
C++ templates for example don't do any text substitution.

Then why do I have to put all my template code in headers for it to be used?

Because you can't export templates yet.
You seem to think this is equivalent to text substitution. It isn't. And it's trivial to show that they aren't.

What else is it if not a text substitution? C++ can't precompile templates like Haskell or C# can, so in the end, it has to literally substitute text to typecheck and compile it, this is why compiler needs the template code. It's not a simple in-place substitution, macros from the context won't make a difference, for example, but in the end, it still is a text substitution.

Well, I'm just doing exercises from books. of course I could use old implementations, but I figure if I struggle to write the code then it's good practice.

making a fantasy console is fun

Attached: helloworld.png (630x232, 12K)

For starters, if it were simple text substitution you wouldn't have to use the template and typename keywords

>if it were simple text substitution you wouldn't have to use #

You can never export generic code in any language.

whats the specs

No it isn't, and I'll show you that it isn't.
template
struct Foo {
T x;
};

Foo f;

This doesn't compile, because it's syntactically wrong.
If templates were just text substitution, this would work, and it'd give you a struct with two integer fields.
>It's not type checked
template
struct Foo {
int y = x;
};

Foo f;

This doesn't compile because it fails type checking. A type isn't an expression.
Also in C++20:
template
struct Foo {...};

Foo f;

Fails to typecheck because int doesn't satisfy the Iterator concept.

Not at any stage do templates do text substitution.
They do AST substitution.

Hope it has its own ASM subset.

Do you have an argument? If lexical analysis is performed at instantiation site then you don't need those keywords. They aren't so it isn't, so it isn't text substitution.

You don't know what # does or what text substitution is.

I wrote a bash script that calls external program. If I press ^C while that external is executing (as child of the script) the external program is terminated but the script is not. How can I make it such that the script is terminated (i.e. to send the signal to the script)?

*They are

maximum COPE
>it's ast substitution
obviously what he really meant and just goes with his comparison to C macros
>you wouldn't need keywords
total nonsense
> fails to compile
use of macros can fail to compile

Good point. Now I think of it, the compiler does syntax check of the templated code, so you need to use `typename` for it to pass, but it doesn't type check, obviously. So it's a text substitution with extra steps.
C macros support arguments and understand `,` as well.
> They do AST substitution.
They quite possibly do, but that's functionally equivalent.
What do you mean? You can export generic types from .NET assemblies (i.e. dlls) since .NET 2.0, Rust crates (rlib) can export generic types and code, so do Haskell packages. In neither of these languages do you need the source code to instantiate a generic type.

if it's too complicated nobody will ever use it, but yes some sort of asm is planned and there are vblank and hblank interrupts. cant decide on if i want registers or not, i.e.:
load a, #byte
store a, dest
load a, src
store a, dest
vs.
mov dest, #byte
mov dest, src

still havent touched sound though, looks like literal hell to do properly
176x144 resolution with a 32x32 8x8 background tiles, 64 8x8 sprites, 4 colors per tile chosen from one of 16 palettes giving maximum 64 colors on screen. color rgb values are fixed but you can customize the palettes to choose between 256 8bit colors RRGGGBB

>You can export generic types from .NET assemblies (i.e. dlls) since .NET 2.0, Rust crates (rlib) can export generic types and code, so do Haskell packages
Those are just binary representations of the source code.
You can't run generic code, it has to be concretely instantiated before you can actually call the function.

If someone wrote program doing lexing + parsing of c++, dumped that to a file, and then wrote a gcc or clang plugin to consume it, would C++ now have exported generic types? Nothing in the language would have changed.

of course with raster effects you can display all 256 colors

>You can't run generic code

Attached: TypeMan.jpg (2136x3216, 325K)

>obviously what he really meant and just goes with his comparison to C macros
He meant what he said. They are semantically different. You can't back out now.
And no, while text sub is shit, AST sub is _not_ shit. So if you're going to backpedal now and claim you really meant AST substitution, then I'm going to go ahead and agree with you. Yes, it does do AST subsitution, and that's the correct way to do it.

>total nonsense
Not nonsense. The compiler parses the template into an AST as soon as it comes across the template. It does not do any lexical analysis at instantiation time.
And you can easily test this:
template
struct Foo {
typename T::Bar x;
};

Here we needed the typename keyword before T::Bar. Why did we need that? Because the compiler needs to know whether Bar is a type or an expression. And it can't determine it from Bar alone because the compiler has no information on T at this point other than T is some type. That is because the compiler parses the template as it comes across it. Not at instantiation time. If it parsed it at instantiation time, the typename keyword would not be required, because at that point in time, it _does_ know what both T and T::Bar is.

Anyone here made their own game engine?

>They quite possibly do, but that's functionally equivalent.
not at all

> Those are just binary representations of the source code.
It's actually compiled into IL because C# generics are type checked and thus can be compiled. Obviously, you can't run generic code without instantiation, no one said that, CLR JIT emits specialization based on the generic IL code. IIRC Rust compiles generic code into LLVM IR.
> If someone wrote program doing lexing + parsing of c++, dumped that to a file, and then wrote a gcc or clang plugin to consume it, would C++ now have exported generic types?
No, because you can't typecheck C++ templated code.

>he meant what he said
autist logic, someone continues to have a conversation and uses the same phrases, the details aren't important and you're talking at cross purposes anyway (you might consider those details important)
>not nonsense
it is nonsense because a language can easily require tokens for text substitution

>Obviously, you can't run generic code without instantiation

Attached: spj.jpg (480x360, 16K)

like a year or two ago, why?

Based SPJ poster.

Haskell doesn't have generics lol

>autist logic, someone continues to have a conversation and uses the same phrases, the details aren't important and you're talking at cross purposes anyway (you might consider those details important)
They're not the same thing. And the "details" are important. Stop trying to back out now, retard.
Even if you meant AST subsitution, you're still retarded because C macros don't do AST substitution, and you can easily test that.

why did you even bother quote replying when you're just going to ignore and contradict the entire post

>it is nonsense because a language can easily require tokens for text substitution
Yes but they don't NEED to require them. C++ needs to require it because it has no other choice.
It's literally impossible for the compiler to know what T::Bar is before instantiation, and that's what the typename keyword is there for.

To summarize this discussion,
C++ is an absolutely retarded pajeet language.

Attached: pepeanime.png (642x336, 120K)

I'm sorry for your inability to read

>they don't NEED to require
talking about a language "NEEDING to require" some syntax or other is bizarre, it depends on a whole bunch of things

No. AST substitution is the right way to do it.
The REAL issue there is ambiguities in the C++ grammar that require you to have to disambiguate in the first place.
In a language with a better syntax, the compiler would know whether T::Bar is a type or expression from the syntax alone, without any extra disambiguation syntax.

"Generics" are just pajeet speak for parametric polymorphism, which Haskell embraces wholeheartedly.

Speak English you dumb fucking ESL.

>in a language with better syntax
To summarize this discussion,
C++ is an absolutely retarded pajeet language.

Actually, you can blame C for the retarded syntax.

Please read my toast. I hope you have fun.

that is english you dumb fucking foreigner

C++ introduced the retarded syntax for generics which is the reason for the disambiguating template keyword at least. Typename was unavoidable when building off C.

>It's C's fault for C++'s retarded syntax
I think you're the thing that's retarded here, mate.

srry

...