/dpt/ - Daily Programming Thread

Bright Friday edition.

What are you working on, Jow Forums?

Previous thread:

Attached: zund_way_to_emmaus656x470.jpg (656x470, 76K)

Other urls found in this thread:

pubs.opengroup.org/onlinepubs/009695299/functions/access.html
personal.cis.strath.ac.uk/conor.mcbride/pub/Frank/test.fk
github.com/frank-lang/frank
en.wikibooks.org/wiki/Haskell
twitter.com/NSFWRedditGif

Reminder to fast from side effects

Attached: anime.png (1000x1300, 786K)

God bless you for using an Easter picture, brother. Our Lord is truly risen, alleluia!

Assuming I study Data Science and ML (I already have a solid background in Linear Algebra and Multivar Calc and Python), would it be easy to get freelance jobs that can be done after work hours and during weekends?

>reminder to not write any useful programs
Typical Haskell.

How do I make a scatter graph in Java? I'm trying to visualize the wins and losses of NFL teams over the past 30 years. Where do I begin lads

>side effects
>useful

is there any decent way of checking if an argument is a valid filename in c like with strtok and strcmp

define valid.

>checking if an argument is a valid

Attached: 751.jpg (598x792, 58K)

>her program can't do I/O

Attached: 5MXN7SX.jpg (281x283, 11K)

you have to write your own thing

it can't but it can be compiled to one that can!

jej

>it can be compiled to one that can!
What did it mean by this?

the IO monad available in the language is functionally pure

monads, effects, linear types

How do make a Java program display an image through a command(eg "if(a==1)) in main?
I know how to make the image class itself and how to view it without a main method

How does an inner class look like in a UML diagram?

>muh moan ads
That doesn't make your program side-effect free. It just hides them under the hood.

>her IO monad doesn't perform purely functional operations on the real world

It does though. Also they'd be effects, not side effects, but that's minutiae.

>purely functional operations
>operations
>purely functional

Attached: cancer-retorno.png (282x66, 26K)

>It does though.
It doesn't. Everything you say will be inherently invalid, because it's impossible for a pure program to do any I/O by definition. Any reasoning you can come up with to get around this fact is known to be invalid from the beginning.

Your computer is fairly pure, that's why you can make sense of it. It's almost entirely logical operations on a bank of memory, with
external interactions (e.g. networking) controlled.

why do you waste your time with uml?

Do you understand ADTs?

>Your computer is fairly pure

>I/O is pure because muh ADTs

The absolute state of FP on /dpt/...

(Algebraic not Abstract)
I'm asking so I can give you an example.

I know how ADTs work. I also know how monads work and how Haskell does I/O. Nothing you can say is going to refute the fact that, by definition, any program that does I/O cannot be pure.

no

For instance
data Console a
= GetChar (Char -> Console a)
| PutChar Char (Console a)
| Pure a
instance Functor Console -- todo
instance Applicative Console -- todo
instance Monad Console where
return = Pure
GetChar cont >>= f = GetChar (\c -> cont c >>= f)
PutChar c cont >>= f = PutChar c (cont >>= f)
Pure x >>= f = f x

getChar :: Console Char
getChar = GetChar Pure

putChar :: Char -> Console ()
putChar c = PutChar c (Pure ())

All of this is pure, except in an abstract sense.
All the code written using this is pure.
Do you disagree?

Use R studios for plots and graphs. also recommend using Python since it's easier to train ML models on there

>what are students

>All of this is pure, except in an abstract sense.
>except in an abstract sense.
What does that even mean? A pure program is interchangeable with the result of its evaluation. You can argue all you like that your program is actually pure because it produces a value that the Haskell runtime them uses to do the actual I/O and produce the real value that you care about, but I'm not buying it. All the code that runs is part of the execution of your program as far as I'm concerned, including whatever happens inbetween the execution of your pure code.

oh god, that dreck is still being taught? you have my sympathies..

I think we have very different mindsets.
Anyway, even if you think it isn't pure, you at least think it controls side effects, which is absolutely worth it. There's no excuse for using an impure language.

there's no excuse to not use dependent types for everything

there's no excuse to not prove every theorem in maths with a theorem prover

You can take C and create a language that is absolutely just as flexible but also has controlled effects, without having too much syntactic complexity or annotations or anything.

do you consider the mutation of state to be an effect?

>I think we have very different mindsets.
Whenever you do a getLine, control is passed to the runtime, which then reads a value and passes it to a pure function that represents the rest of the program. You may not have written any impure code yourself, but how do you figure that the stuff that happens as a consequence of the execution of your program isn't part of your program?

>even if you think it isn't pure
Again, to be clear, the Haskell code you write is pure, but that's not all there is to the program.

>you at least think it controls side effects, which is absolutely worth it.
>worth it
That's a subjective matter. If I had to do the sort of work I do in Haskell, it simply wouldn't be up to specs, so it's as good as getting nothing done. So no, it's not worth it as far as I'm concerned.

If it's not a compiler detail.

The point is that conceptually, you can write a Console program. That program is just a pure value. You can choose to have that program compiled into an effectful program that actually does something interesting, or you can just run it in a REPL or something with fixed input instead.

No, it is not a freelance friendly field, unless maybe you have a PhD.

>That program is just a pure value. You can choose to have that program compiled into an effectful program that actually does something interesting
You can take this logic to all sorts of weird places. Have a Haskell program that just dumps a string of imperative C code and then say "the program is just a pure value". Then you can write a C evaluator that executes your code on a virtual machine using a state monad or whatever, and the virtual machine starts from a fixed state that is the input to a pure function. Then you can say everything involved is pure unless you choose to compile it into a real executable.

If you mean you want to check if the file exists:
pubs.opengroup.org/onlinepubs/009695299/functions/access.html

Otherwise "valid" filenames depend on the filesystem in use.

was hoping someone could help me architectually/conceptually:

trying to make a python script that has the ability to send a kill signal to all devices aka an interrupt at any time. problem is I'm using time.sllep() which is a blocking function

how can i get around this? I've tried looking into threading but i cant really envision exactly how to implement it for this case

I think conceptually it's a bit different because there's the pure computation aspect inside the language itself. Almost everything is just beta-reduction. Plus the way it interfaces.
It's not at all like passing strings around though I see what the argument is supposed to be.

Another example is that it really is just a value. You can manipulate it like any other. If it's a user defined example (rather than a primitive for interfacing with a compiler), you can run it purely for instance.

i think the introduced complexity is significant enough.

for effects to be pleasant to use (i.e. not a repetitive, deeply nested mess) you need fmap and some kinda syntactic sugar like do-notation. (frequent wrapping and unwrapping also has a minor perf implication that we will ignore here).
for do-notation to be usable with all kinds of effects you need to generalize the notion of "effectness", introducing something like monads.
combining stateful code with any other kind of effect is common in production and incredibly common in a language like C, so now we need something to combine different effects.

as you can see there's quite a huge load of shit associated with controlled effects, as you call it.
it becomes even worse when you really need to care about perf - non-trivial algorithms that aren't just a composition of a few functions in the haskell stdlib are often more naturally and easily implemented imperatively (which is one of the reasons why FP langs are so uncommon amongst competitive programmers, despite them being perfectly capable of using them).

basically, whenever you can easily come up with a solution that's just a composition of existing solutions FP code is a lot cleaner than the imperative counterpart - but sadly the real world is often inherently ugly.

personally i think that it'd be a good start if devs documented effectness more, so other devs are aware that some code they use is effectful, without necessarily being forced to use the whole apparatus required for these effects to be fully 'controlled'.

In an algebraic effects language it's much cleaner, but you can still have custom handlers and stuff. Here's an example:
personal.cis.strath.ac.uk/conor.mcbride/pub/Frank/test.fk
github.com/frank-lang/frank
In this language, "map" is the same as "iter". It's effect-polymorphic.

>there's the pure computation aspect inside the language itself
>Another example is that it really is just a value. You can manipulate it like any other.
I don't think Haskell do block with I/O operations is all that different from a string of imperative code when you get down to it. In both cases you have a value that can be thought of as a bunch of instructions to be evaluated.

You can write pure functions in (standard) Haskell, with the only exception being exceptions. You can't in C. Any C function might perform side effects.

>You can write pure functions in (standard) Haskell, with the only exception being exceptions. You can't in C.
You can write pure functions in C just as you can in any other language.

>Any C function might perform side effects.
"Might". Doesn't mean it has to. I think the real value in Haskell isn't the "purity" meme (which is rendered meaningless when taken to its ultimate logical conclusion), but that it doesn't let you do side-effects willy-nilly.

Well I mean you have a type level distinction. C doesn't have a type for pure functions.

i'll look into the paper, thanks

i wanna point out that i'm not closed-minded to the idea (it's very desirable, for sure), just that my experience is that the systems for controlled effects that have been sufficiently tested are too annoying to use to be commonplace in production.

Reminder that your language is useless, if you can't beep in the console

>Well I mean you have a type level distinction. C doesn't have a type for pure functions.
I know. That's what I meant, and I think that's the real value in how Haskell handles side-effects; not simply programs being "pure" on the surface. You can use monads to produce programs that are pretty much isomorphic to imperative ones, and every bit as difficult to reason about, while still being technically pure.

You can produce ones that are difficult to reason about, but you are more likely to produce modular code that's easier to reason about.

I'm looking at making myself a bit of a small time software developer to do scripts/apps/whatever someone wants.

To aid in this, each project I do, I'd like to build a library of components, so next time I need to make a new version of it for a new customer, I have a number of components I can already plug together.

Any recommendations on how best to do this?

And the compiler can do better optimisations.

employed sepples programmer here

Attached: 1492547371042.jpg (196x250, 8K)

Picking java back up. I knew some java and I stopped after I started working and I started building small little projects.

>You can produce ones that are difficult to reason about
That's not the point. The point is that purity itself doesn't help you much. You can use monads to obscure the flow of data in exactly the same way badly written imperative programs do, while still maintaining purity. The silver lining is that you at least can't have true race conditions, but you can still have bugs that look like them.

>you are more likely to produce modular code that's easier to reason about
I'm not sure about that.

Painful.

Attached: 1490816588368.png (750x1091, 211K)

>they don't use __attribute__((const)) or __attribute__((pure))

Exquisite.

>using implementation specific behavior
You are the reason that building Linux with Clang instead of GCC is better described as a port than a patch.

>To sort a list you must extend a ..
KEK. True. Though you can pass the list to the constructor of a sortedlist.

>pass the list to the constructor of a sortedlist.

Attached: dr.jpg (1400x933, 258K)

c++ brainlet here
What does "Uninitialized reference member" mean?
I'm getting that on a class constructor, I have no clue what it means. Google didn't help me much, most cases I found look nothing like mine.
The constructor is very simple:

Component::Component (GameObject& associated){
Component::associated=associated;
}

pls no bully I'm a true brainlet ok

>ECS
Fucking cancer. Get this garbage out of here and learn Haskell.

Wonder if you could do ECS using rows or effects

Same perf as sorting except that you are creating a new object.

It means you haven't initialized a reference which is a member of the class.

Protip: you need to initialize it in the constructor initializer list, not the constructor body.

I know some Haskell. Can't use it tho, this is a uni project and CS professors are very autistic, as most people already know

>find the largest member in a list? just pass the list to a LargestMember constructor
>find the sum of two numbers? just pass the numbers to a Sum constructor
The absolute lack of getters and setters on instances of JavaProgrammer...

I'm not him and I didn't read all your posts, but having monadic side effects does help with modularity and reasoning. Reflex is an example of that: its whole interface is independent from the underlying monad, which represents the concrete implementation. There's both a pure implementation and one with side effects. The former serves as a reference for the other implementations, while the latter is actually used in practice, since FRP programs usually deal with the external world.

What do you mean? you can write your own getters and setters for any object.

All their members are private to maintain the absolute state.

Hi guys. I work with SQL everyday but am not good at it (I basically do a bunch of officedrone stuff with internal software, and often have to pull data from SQL for a bunch of reasons)

Do you have any good book reccommendations?
I stole a book from work call 'Sams learn SQL in 10 minutes' and found a PDF online of Alan Beaulieu Learning SQL. Do you think these will get me enough info?

I can do basic shit like Select, from, group by, order by, update, delete, basic joins (though I basically just use outer joins without any thought). What would you describe as 'intermediate' knowledge? That is where I want to try and get, I don't really need to do much more than the basics but feel I should use the opportunity of having a huge database.

>t. too brainlet and soy to write getter and getter methods for every field you wish to make available for modification

>the sheer level of oblivious autism

just use lenses

>t. butthurt M$hill or sepples code monkey

How do you pronounce SQL?

>(new KysFactory()).createInstance("withFire").apply(you);

ess cue ell :^)

hehe

I say Ess Queue Ell which I prefer to Sequel, I only pronounce acronyms as words when they contain vowels (so I prounce AIDS as AY-DES and HIV as 'Heev' but I pronounce BBC as Bee Bee See)

How to turn myself from spaghetti python coder (self taught, never use classes, init method etc) to someone with proper etiquette?

en.wikibooks.org/wiki/Haskell

memes aside what does this even mean?

"The language is, as of 2011, the functional language on and in which the most research is being performed."

haskell is academia's main masturbation material since 2011

>what does this even mean?
Means you've got lots of Haskellers looking for a way out of Haskell without outright leaving it.

plt wise, maybe. but now i would say most of cs researches are using cuda or c++

No, most cs researchers use fucking python.

Read Clean Code, unironically.

>the functional language
A programming language that's focused on the functional paradigm.
>in which the most reasearch is being performed
It's used to implement programs used in research.
>on which the most research is being performed
It's used as the subject of research. For example in areas like compiler design, language design, type theory, etc.