/dpt/ - Daily Programming Thread

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

Attached: 1555936849419.jpg (850x1096, 194K)

Other urls found in this thread:

alexgaynor.net/2019/apr/21/modern-c -wont-save-us/
twitter.com/SFWRedditVideos

>scala is functional

I'm looking at other people's Emacs distributions and "borrowing" their functions to add their functionality to my Emacs config

I'm learning so much elisp this way

Why don't you all even started to learn Haskell ?

Attached: file.png (643x844, 490K)

Imagine having to program your own IDE

wrote this today
def checksum
if @checksum or File.exists?(@abs)
return @checksum ||= `md5sum "#{@abs}"`.scan(/\w+/).first
else
return @checksum = $connect.call(self) # todo unfuck this
end
end

haskell programmers at it again
cute best girl

Attached: core GHC package.jpg (151x73, 5K)

Most knowledge of Elisp can also be applied to other Lisp dialects but honestly I'm having a ton of fun learning about it so I don't see no reason to stop

I'm writing a GUI thing with Julia, but realized that in reality, I just need to display some mixed markdown/latex files and parse user keyboard input for interaction.
Basically, there is the main logic, which determines what file to show next based on keyboard input and the viewer, which would ideally be the system's existing, default one.
What's the most elegant and simple way to approach this?

Imagine relying on some other programmer to choose the features of your IDE for you.

I learned Haskell in university. it was a very interesting language, but real-world Haskell is just such a fucking mess that I can't be bothered getting into.

it really isn't though

>real-world
Was your university in a "fake world", i.e., in a fictional story?

It's a language that is used very differently in practice compared to the "ideal" Haskell that people teach and people claim that Haskell is like.
When it looked at some open-source Haskell projects, literally fucking everything is a monad.

>literally fucking everything is a monad
So? I thought your university """""""taught""""""""" you Haskell?

>"ideal" Haskell that people teach
beginners haskell more like

Attached: 1555336317020.jpg (1920x2163, 1.25M)

The point is that practical Haskell isn't very pure

At an extremely surface level. I don't be claim to be an expert in any regard.
Basically, I can write an compile a very simple program, so I'm ready for prime time and deserve $300k starting for my knowledge.

>isn't very pure
How so? It seems like you're just rambling on with no real understanding of what you're saying now.

it depends on what you're doing and how competent you are

What does Haskell UI code look like? It's seems hard to imagine decent UI code without at least some mutation going on.

How exactly did you """"""learn"""""" Haskell if you think mutation is somehow incompatible with purity?

you can do it in a variety of ways, one would be FRP, another would be the traditional way but handling 'effects' with some sort of monad

I didn't learn Haskell. I'm not the other guy.

What does "purity" refer to if not immutability?

>What does Haskell UI code look like?
I don't know, you're the expert on how impure open-source Haskell projects look like.

>It's seems hard to imagine
Why? Because of your imperative little brain?

>I'm having a ton of fun
that's great but sadly unrelated to how useful something is

>What does "purity" refer to if not immutability?
Did you try looking this up before asking this retarded question? "purity" refers to "purity".

It's funny how Haskellets act like they're smarter than everyone else yet the whole Haskell shtick is "state is too difficult to manage, lets remove it"

>"purity" refers to "purity".
So you don't know what purity means in functional programming?

They apparently are smarter, since imperitards can't seem to grasp basic concepts a kid could understand. Seems like shitlangs really do fuck with your brain at a very deep level.

Perhaps. I like functional though. I use F# for almost everything.

you can model a state machine very simply
s0 = init state
s1 = step(s0)
s2 = step(s1)
...
return sn
this is your fault for being an autistic retard
learn how to reply to people like a normal human being

>So you don't know what purity means in functional programming?
No, I don't. Look it up on the internet if you care enough about asking retarded questions.

OMG, JavaScript totally rocks!

Attached: 97bda3295566b1a65639b7dbe2c58bd9.jpg (564x846, 54K)

But I already know what purity means.

>basic concepts a kid could understand
like what exactly?

>FRP
Not who you're replying to, but this isn't something I've come across before. What is the core of that? Is it possible to apply that to non-functional languages?
A quick googling doesn't give very accessible results.

I'm writing a GUI from scratch (in C), and I'd like to implement it in a novel way, even if it doesn't turn out to be a great fit.

>What does "purity" refer to if not immutability
Evidently not.

Sure, but I don't find that very simple with a lot of UI projects. Trying to do complex UI updates like that gets stupidly messy fast to the point it's much more maintainable just to use a little mutation here and there.

functional reactive programming
C is a bad idea because you would ideally want lambdas and generics

>generics
no ty im happy with my macros :)

Yes, I figured out what it meant, but what does it actually mean as opposed to a normal way of doing it.
>C is a bad idea because you would ideally want lambdas and generics
Nothing some callbacks won't fix.

>Is it possible to apply that to non-functional languages?
Yes. That's basically what React.js is and shit like that.

the reactive extensions libraries are pretty sweet. I use them for everything. rxjs is the JS version.

it is when you write combinators and higher order functions for manipulating them
do x

But that proves I do know what it means. You're confused.

>macros
You mean the crippled garbage Ctards dare to call "macros"?

>that proves I do know what it means
>What does "purity" refer to if not immutability
Evidently not.

are x and y not being mutated here?

Did you not read ?

>Is it possible to apply that to non-functional languages?
Yeah, it is reinventing mvvm with wpf

they're sort of like event systems. i haven't personally used them much. you could try looking at the docs but it's a bit of a mess of links. i've found:
yampa, reflex, netwire (all haskell packages providing some frp style functionality)
no, the whole thing is represented as a function from an input state to a pair of an output state and a result. those functions are chained together to give a big function. for example, get takes the input state and gives back the (unchanged) input state and also the input state as a result. put ignores the previous input state and returns the new state (whatever param you gave it) as well as an empty value signifying something like C's void (i.e. no interesting return value)

Yes. But that's a different post.
is x

MVVM is just a type of FRP. MVVM is used in a lot of frameworks besides WPF too. Microsoft sure as fuck didn't invent FRP.

"purity" means that x = y implies f(x) = f(y) for all x,y and f of the appropriate types.
A compiler for a language where you only require "immutability" can still randomly insert arbitrary new values for f(x) without mutating anything, thus making your language both "immutable" and "impure". This shows how "purity" and "immutability" can't refer to the same concept.

Is
let x = 5 in (x + x)

mutating x?

No, it's the same as this C code:
int x = 3;
x = 10;
We don't mutate x on the second line. We create an entire new state for the entire program where x has now taken the value of 3 and the old program state is left untouched, meaning that this code, and all C code really, is purely functional.

Immutability only refers to the actual human written source code. It never refers to what the compiled code does. That doesn't matter whatsoever so long as it behaves as described in the high level language it was compiled from.

Which is fine un

type State s a = s -> (s, a)
-- a stateful computation, with a state s, and a "result" or "return" a
-- represented as a function from s to a pair (s, a)
get :: State s s
get = \initState -> (initState, initState)
-- get leaves the initial state unchanged and also returns it as a result
put :: s -> State s ()
put newState = \initState -> (newState, ())
-- put ignores the old state and gives back the new state, as well as an "empty"/C void result: ()
ret :: a -> State s a
ret x = \initState -> (initState, x)
-- ret simply turns a value into a stateful computation returning that value

chain :: State s a -> (a -> State s b) -> State s b
-- chain will take a stateful computation returning a, and then a continuation expecting that a and continuing with a State s b computation
-- you can think of (chain s1 (\x -> s2)) as { x = s1; s2 }
chain s f = \initState ->
let (newState1, result1) = s initState
in (f result1 newState1)
-- call the continuation with the result and the new state

modify :: (s -> s) -> State s ()
modify f = chain get (\x -> put (f x))
-- we can use chain to define modify
-- modify f: { x = get(); put (f(x)) }

notice we've only used lambdas, pairs and let bindings - no mutation!

How is this a response to my post? You can require a language to not have any variable-mutating constructs and it can still be "impure".

>mfw my puny imperative code will never be as elegant as this

which is fine until you need to actual change the actual rendered UI. Unless you want to rebuild the entire UI tree every time you make an edit to it anywhere. Even then you need to edit the window to render the new UI tree or whatever.

Code I've seen that attempts this shit just looks messy as fuck because UI doesn't lend itself well to pure immutability. Which is why it hasn't taken off.

imagine being this retard

>t. salty about ms inventing functors
anyways, I was referring to the era where every OO lang started spreading the 'reactive' meme like it is something entirely new. I think java devs are still at it lol.

Are you suggesting having variables in your functions makes them somehow impure? Variables can still be immutable, which is generally the goal in pure FP.

in haskell the main unit of computation is evaluating functions by substitution and pattern matching. you can argue that programming a pure description of impurity is kind of impure programming, in an embedded language sort of way, but overall most haskell code is unambiguously pure with a few contact points for IO (and not just technically pure, modulo non termination)

You seem to have serious reading comprehension issues.
Let f(n) = n in some language which doesn't support mutating any data from within the language. Now my compiler for this language will just change every call f(n) to 0 for every odd-numbered call to f in the program, thus achieving both "immutability" and "impurity".
Didn't even read this post, as it's not a reply to what I'm saying.

i mean if you look at , the whole thing is totally pure, but it's representing an impure concept. i would say it's an advantage to have pure functions in your language as a separate type (or something you can check in an argument to a function), even if it's just for reasoning about. in fact i'd probably support local mutation in the same way D's pure or C++'s constexpr does/will do(?), so long as it's referentially transparent

That post you replied to was supposed to be facetious, but that really is the argument for it.
When you really think about it, it's just forcing statefulness in pure functional programming or it's admitting that obviously stateful things like pure imperative statements are stateless.

>stateful things like pure imperative statements are stateless
Retard who doesn't understand the distinction between "shared mutable state" and "state" spotted.

there are multiple techniques related to this
first, purely functional data structures. for example, to push a value to the front of a pure cons list, we just need to return a cons cell, we don't need to rebuild the list (it's pure and won't change)
you've got other stuff like linear and uniqueness types, region types, etc
and then there's obviously ways of guaranteeing actually imperative code is referentially transparent and thus calculates pure functions

how is anything considered "state" if it isn't mutable

Retard who doesn't understand the distinction between "mutable state" and "state" spotted.

fuck both of you desu not sure why i bother explaining stuff when you just want to call each other retards

Attached: 1554760963915.jpg (1280x720, 810K)

haskell as SHIT

yes, that was the question i asked

Cringe

Maybe learn to use a search engine instead of asking retarded questions.

>Cringe
"Cringe".

not knowing what your obtuse definition of state means isn't a retarded question

It doesn’t matter what the compiler does whatsoever though. “Mutation” only applies to what happens in the actual language. All kinds of mutation is going happens behind the scenes on any modern computer.

Thinking that the observable state of a program has to be mutable to be called "state" is plain retarded. Did you even read this thread? Someone literally wrote down an example of a state machine where no data is being mutated. Just look around, even someone like you should be able to find it.

Redundant cast at:
haskell as SHIT
^^
haskell is of type SHIT.

What is it with /dpt/ and autistic arguments over what vague programming terms mean?

well it sounds like you're just kicking the can further down the road, you can say the contents of this variable won't internally change, but the variable itself still can, so you are changing some state somewhere

/dpt/ posts are 90% that guy in CS class with no friends who thinks he's smarter than everyone else

alexgaynor.net/2019/apr/21/modern-c -wont-save-us/
Is he right?

Attached: 1363-HGE-28F-141119_MS_Enviro_Bjarne_Straustroup_055-RGB.jpg (1200x800, 520K)

Well said

he means like for example, you could have a compiler that turned
s = init
s = f (s)
s = f (s)
s = f (s)
return s

into
s0 = init
s1 = f (s0)
s2 = f (s1)
s3 = f (s2)
return s3

and realistically your compiler probably has a phase like this when it's mucking around with register allocation

C++ isn't memory safe? what a hot take

>'''modern''' C++
retard

I'm actually convinced that you have reading comprehension problems. Let me make it even more braindead for you:

Our goal is to show the existence of a language in which "no mutation happens in the actual language" and yet the language is "impure", i.e., does not guarantee the purity of every function defined in the language. To this end, let L be a language supporting function definitions and defined by the sole property of not allowing for "mutation" to "happen in the actual language". Let f(n) = n be a function in language L. Now we stipulate in the language standard that every odd-numbered call to f has to return zero. The language still obviously does not allow for "mutation to happen in the actual language", but the program
f(3)
f(3)

has the same term evaluating to different values. Thus showing how the language is "impure".

why would you use 4 variables instead of 1

Why would anyone capture a by value parameter as a reference
This blog post is so fucking retarded, you have to be a textbook case of mentally disabled to do these things
>grug stab grug in eye
>why grug eye hurt

it's more functionally pure.

pure functions are easy to reason about
depending on the circumstances it could be more or less efficient, e.g. it'd be retarded for those to be atomic updates on memory shared across threads for just an int or something

variables arent functionally pure
the term "variable" should tip you off

those aren't variables. those are let-bindings.

they are though, in f(x) = x * 2, x is a variable. variable doesn't imply impure.