« first day (2275 days earlier)      last day (945 days later) » 

11:26 AM
What are you supposed to do if someone asks an ok question, you answer it, and then they author deletes the question?
 
here, then we undelvote and upvote your answer that prevents deletion
 
Is undelete-vote a higher rep privilege?
I was asking because of this question where I can't see a way to vote for undeletion.
And I really want a badge:P
 
@flawr 10k, yes
1 more undelvote needed
 
11:42 AM
Ah I see, thank you!
<3
 
 
2 hours later…
2:12 PM
@flawr Undeleted, and upvoted your answer to prevent deletion again. Although I don't understand the answer... I hope it's worth upvoting!
 
@CrisLuengo Thanks:)
In haskell a lot of things are done via pattern matching, which requires a little bit of relearning at the start
so a list comprehension that just clones a list would looks like so: [x | x<-myList]
but if the elements of myList are tuples, and you want the tuples where e.g. the first entry is 42 you could just write [(42, x) | (42, x) <- myList] (of course this particular example is a bit uselss, but I hope it illustrates what you can do:)
or many functions you define will process a list, and you usually do this by using multiple definitions with pattern matching: first you define what happens with the empty list, then you define what happens if there is at least one element in the list:
sum [] = 0
sum (x:xs) = x + sum xs
(x:xs) is another way of writing a list where x is the first element and xs is the remainder of the list.
In python you can do some pattern matching too, but only with tuples and lists, and only with referring to the structure, not the actual values
def sum(l):
  if not l:
    return 0
  else:
    x, *xs = l
    return x + sum(xs)
it appears in 3.10 it is possible to match for values: python.org/dev/peps/pep-0622
 
2:54 PM
That PEP is actually quite useful.
I thought Python had as philosophy that there should be only one obvious way to do something. Obviously they need to keep adding to the language to allow for more ways to do the same thing! :D
 
it's somewhat controversial, mind you
but it can remove a lot of bloat in good use cases
 
Haskell really looks like a totally different paradigm than what I'm used to. Maybe I should learn a bit, like I did with APL. Just to broaden my perspectives on programming.
 
I'm not a huge fan because elif should be good enough for anybody :P But, unlike asspressions, this is harder to abuse.
and instead of having to do elif isinstance(p, Point) and p.y == 42: you can do case Point(x, 42): which I have to admit is nice (not nice and common enough to add new syntax, but nice)
 
Hum. Google for "asspressions python", and I get 10 results back. Mostly to SO Python chat room.
 
hehe, you're welcome
 
2:58 PM
So what is it? Something invented in that chat room? There's no PEP for it?
 
lesser beings call it assignment expressions, shit of a feature from 3.8, PEP 572
it's the one that made Guido step down as BDFL, but only after forcing that shit of a feature through despite massive pushback
 
Oh, I get it now. ASSpressions. "Ass" as in assignment and asshole.
 
yup
it can catch on any year now
 
LOL
In C and C++ all assignments are expressions, and it's hugely useful.
In Python they could probably have changed the assignment operator to return its value, would have been more useful and more understandable. Python's a = b = c is wonky anyway.
I love doing while(data = read(...)) { /* use data */ }
 
@CrisLuengo Highly recommended:) I'd be happy to help/discuss if you so desire!
 
3:03 PM
@flawr All I need is a pointer to a tutorial that doesn't assume I know nothing of programming. Do those exist?
 
Lemme check
 
@CrisLuengo yes, we definitely need a way to do if self.kill_all_humans = True: ... in Python
 
@AndrasDeak What Python really needs is some good curly braces. There's not nearly enough of them in Python.
I use cell arrays in MATLAB just so I can see those curly braces everywhere... :D
 
from __future__ import braces
 
PEP 43251: Allow for curly braces for flow control, instead of stupid indents. So we can write code with misleading indentation.
@CrisLuengo I didn't see the answer(has not refreshed the page I guess) and found the answer on my own, so wouldn't waste anybody's time :) — sdsad asdasd 33 mins ago
 
3:10 PM
@CrisLuengo but shouldn't they have gotten a warning anyway?
 
I guess they deleted at the same time you posted the answer.
 
the timestamp says there was about 4 minutes between asnwering and deletion. Well anyway, thanks for the help:)
 
@flawr Don't know. I presume there's always a dialog box "are you sure?". I don't think I've ever deleted a question of my own.
@flawr Then they should have seen the answer. SO always updates the page, or at least says "there's a new answer, click here to refresh". And they should also have gotten a notification.
 
there might not be a warning, but there's definitely an ajax banner when there's a new answer, and an instant notification that's very visible
 
@CrisLuengo I couldn't find anything that assumes some programming experience right now. But the universally recommended book is learnyouahaskell.com which I used too. But for the first chapters I'd just look at the code snippets and ignore the text unless there is somethign you don't get.
 
3:13 PM
@flawr Awesome, thank you!
 
It must be great if it could teach programming to a mathematician! (Just kidding; haskell is not a real programming language.)
 
And for fiddling around you can use TIO, but more helpful is having GHCI on your computer. This is an interpreter that easily lets you load a file in there (:l file.hs, or reload it using :r) and play with the definitions. It is exceptionally handy to inspect types (:t yourVarOrExpression, or alternatively :i) to get what's going on, because everything in haskell is types and functions.
Also don't start by trying to write full programs that print stuff or interact with stuff, you first need a grasp on the typeclasses to do that (especially the "IO-Monad"), so first I'd just stick to writing stuff that you interact with on the interpreter.
@AndrasDeak I really liked the programming part, but then they wanted us to compile and execute stuff...
 
@flawr I like that API! It was clearly designed by a vim user.
 
@flawr I seem to have ghci already installed on my machine. No idea why it's here, but it's here!
 
3:29 PM
@CrisLuengo I bet you're a sleephaskeller. You write Haskell in your sleep but don't remember it when you wake up!
 
And using :t 5 I learned that 5 is a function that returns the value 5. Someone was smoking weed when designing this language... :)
@flawr "IO-Monad"? But IO requires side effects. You can't have IO in a purely functional language!
 
@flawr Maybe
 
@CrisLuengo That's only a problem for people who actually want to execute their programs and do something useful.:P
But it is a really nice abstraction that still makes sense. You can imagine that writing your program is basically building a huge pure function, and whatever is spit out when applying the function to inputs will be the outputs.
It's more a philosophical question:)
 
that's... exactly what functions do, don't they? :P
 
But in practice it makes all the "impure" things really obvious and explicit.
 
3:37 PM
Sure. But it's kind of limiting though. I don't think the Haskell compiler could be written in Haskell, could it?
Oh, I was wrong. "GHC itself is written in Haskell,[7] but the runtime system for Haskell, essential to run programs, is written in C and C--."
 
@AndrasDeak functions don't do anything:P
 
@flawr You said that they "spit out" something.
 
the only good function is a dead uncalled function
 
Oh, you said that something is spit out when the function is applied to inputs. So it's not the function spitting out something, but the system? What is the mental model here?
 
So the idea of e.g. the IO monad is that whenever you get some input from the "outside world" or print some output to the outside world, the outside world is basically an additional object that gets passed into your function, and the output of the function is a new outside world
so a print() function in python just takes a string and does nothing
in haskell you could think of it as taking a string AND the state of the outisde world, and it returns the new modified state of the outside world
or similarly if you use an RNG you always need some state to generate the next random number
so get_random_number() would similarly take the rng_state as an argument, and return the number plust the new state
 
3:48 PM
I see. That makes some sort of sense. You're not changing a status, you consider the universe as an input and a new universe is the output
 
but the Monad typeclass in haskell let's you deal with that state handling in a more comfortable way
 
Anyway, it's funny that the Haskell compiler converts your program to an imperative language for execution. :D
 
@CrisLuengo exactly, you can't change stuff you can just define new stuff:)
@CrisLuengo well there is not much choice:)
but it shows how the imperative paradigm was dictated from how the machines operate
but the functional paradigm was modelled from a way (one of many) how you can think about things
this is broadly generalized but I think it is nice to consider languages that didn't slowly grow by checking what the machines can do and then simplifying or abstracting things away, but that come from the completely opposite end in that we first think about how we'd like to reason, and then try to get the machines to do the stuff for us
 
Yes, I agree. This is why I'm interested in learning a bit more about these languages. APL has a similar background: it originally was a notation to reason about algorithms, it was only turned into a programming language later.
 
 
1 hour later…
5:13 PM
@flawr that is the crux of a programming language that was not meant to be used for programming :P
 
 
3 hours later…
8:12 PM
@CrisLuengo before I forget hoogle.haskell.org is great for searching for functions. You can also fuzzily search for function signatures.
 
like "5"?
 
 
2 hours later…
9:47 PM
@flawr Haskell is disappointing... I'm following the tutorial, it explains how to find right triangles with a given perimeter. But this never completes:
let triangles = [ (a,b,c) | c <- [1..], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24 ]
It can't tell that if c>24, then a+b+c==24 can never be met, so it can stop iterating. So sad... :(
 
10:17 PM
As you noticed this can't possibly terminate the way it is written here. You'd have to use 24 as an uppe rlimit for c.
is that in this tutorial???
Ah in the example it shows [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]
for some curious reason the upper limit for c is set to 10
@CrisLuengo It's not Prolog:)
but if you know a solution exists and you just want to find one, then it woudl be quite idiomatic to write
oneTriangle = head [ (a,b,c) | c <- [1..], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24 ]
even though we have a list that might possibly be infinite (or doesn't even terminate) due to the lazy evaluation it will just stop after finding the first solution
or instead of head you can use take 5 to just get 5 possible solutions
anyway, the following chapters are hopefully a little bit more fun:)
 

« first day (2275 days earlier)      last day (945 days later) »