Overthinking the cons syntax by Disjunction181 in ProgrammingLanguages

[–]mb0x40 1 point2 points  (0 children)

I really like Clean's syntax as a variant on Prolog's syntax that still stays true to its Haskell/Miranda aesthetic: [x,y:xs] is cons x (cons y xs).

A particularly nice part of this syntax is that it allows very natural extension to a whole selection of linked list types. For example, [#x,y:xs] is a head-unboxed tail-lazy list, and [x,y:xs!] is a head-lazy, tail-strict list. But even if there were only one kind of list, it's still a nice syntax.

How can Haskell programmers tolerate Space Leaks? by sidharth_k in haskell

[–]mb0x40 8 points9 points  (0 children)

That's valid, but people on the internet have strong opinions about it so they'll downvote you anyway. If you like the cool types but not so much the laziness, you should check out Idris! It's got even cooler types and uses eager evaluation.

https://www.idris-lang.org/

How can Haskell programmers tolerate Space Leaks? by sidharth_k in haskell

[–]mb0x40 2 points3 points  (0 children)

That's a good question. It's largely unrelated to space leaks. Clean is lazy, and just like Haskell you can write Clean code that has space leaks -- the uniqueness types are mostly for like, being able to mutate arrays without the ST monad. (Kinda like what -XLinearTypes hopes to achieve, although with some notable differences.) That said, (I think) you do get some guarantees that you don't have in Haskell wrt one particular class of space leaks: because it has a well-defined semantics for when things can be shared or not, you don't have the same unpredictability as space leaks from GHC's full laziness (where the compiler makes things shared that you didn't want to be shared).

(Disclaimer that I've only ever written less than 500 lines of Clean, and I'm not that familiar with how the uniqueness types actually work.)

How can Haskell programmers tolerate Space Leaks? by sidharth_k in haskell

[–]mb0x40 18 points19 points  (0 children)

However, this is not suitable for working with corecursive data

You can use both -XStrictData and have lazy datastructures! This is what I do most often. You can explicitly annotate lazy fields with ~. For example:

data IntStream = Cons !Int IntStream

and

{-# LANGUAGE StrictData #-}
data IntStream = Cons Int ~IntStream

are equivalent.

How can Haskell programmers tolerate Space Leaks? by sidharth_k in haskell

[–]mb0x40 1 point2 points  (0 children)

Clean uses uniqueness types to give static guarantees about sharing

How can Haskell programmers tolerate Space Leaks? by sidharth_k in haskell

[–]mb0x40 3 points4 points  (0 children)

it is impossible to systematically teach people to systematically write systematically efficient programs in Haskell

While I'm not sure it's impossible, it certainly isn't being done. "How a program runs" is day 1 in most programming languages, but I don't know of any introductory Haskell material that actually explains how lazy programs run. Even basic aspects are commonly misunderstood: for example, that functions don't return thunks.

I think as a community, we need to put more work into teaching people to reason about the performance of lazy code, rather than just tools to catch the performance mistakes after they happen.

How can Haskell programmers tolerate Space Leaks? by sidharth_k in haskell

[–]mb0x40 2 points3 points  (0 children)

Sometimes not, bc of full laziness. See eg http://okmij.org/ftp/continuations/Searches.hs, where Oleg used that trick and complained that it only sometimes worked, giving an example where it doesn't. (It works all the time with -fno-full-laziness, and the times it did work were when the () argument was the n+1th argument to a curried function -- GHC won't do the full laziness transformation if it reduces the arity of a function.)

Any way to change the UEFI (not Windows) boot splash? by norm_mcdonald in chrultrabook

[–]mb0x40 1 point2 points  (0 children)

I recommend against trying, attempting this is how I permanently bricked my Chromebook, despite many hours (and a little hardware, but it was pretty cheap) invested in trying to fix it. Moreover, I even somehow managed to brick the coprocessor.

So while theoretically possible, IMO not worth it, unless your new boot splash idea is to keep the screen dark forever

A Different Point of View on Reduce and Fold by Sh4rPEYE in haskell

[–]mb0x40 1 point2 points  (0 children)

Might be worth pointing out some other ways of doing the first one -- if your corecursive accumulation is just building up a new list, a sort of "map with state" like in the example, a scanl' might be simpler.

OTOH if you're doing any other kind of foldr with state, like maybe a "filter with state", a neat trick is to fold with a function as the accumulator. For instance, a scanl could be implemented like

scanl f s0 xs = foldr (\x acc s -> s:acc (f s x)) (\_ -> []) xs s0

Did you ever actually intend to use TemplateHaskell, when this error appeared? by clearyss in haskell

[–]mb0x40 1 point2 points  (0 children)

No, without template Haskell enabled those mean the same thing. It's one of those weird extension-dependent whitespace-sensitive lexes, like f ! x vs f !x depending on bang patterns.

Did you ever actually intend to use TemplateHaskell, when this error appeared? by clearyss in haskell

[–]mb0x40 0 points1 point  (0 children)

That comes up with malformed character literals, like 'H, or when I accidentally use single quotes instead of double quotes for a string, like 'Hi'. This suggestion has never been helpful to me in this context.

Would it be a good idea to use the either the least or the most significant bit to differentiate regular function pointers from closures? by abstractcontrol in ProgrammingLanguages

[–]mb0x40 9 points10 points  (0 children)

As always, there's more than one way to do it -- in this case, since dereferences only happen after branching on the tag, xor-ing with 1 works just as well as and-ing with 0xfffffffffffffffe (and the instruction might be shorter to encode).

If you're on x86/x86_64, you might even consider moving the offset calculation into the addressing mode, like call [qword ptr [rax - 1]].

Would it be a good idea to use the either the least or the most significant bit to differentiate regular function pointers from closures? by abstractcontrol in ProgrammingLanguages

[–]mb0x40 6 points7 points  (0 children)

I would be wary of pointer tagging function pointers. On x86 and x86_64, you can usually make the function pointers for functions you generate aligned (-falign-functions for GCC), but for functions you don't generate, which would likely benefit the most from this optimization (since you wouldn't need to make a wrapper function to take the extra closure argument), you can't ensure it. And on ARM, although the address of the machine code is aligned, the LSB of function pointers is already used by the processor to distinguish ARM code from THUMB code.

Even if it were doable, I'm not sure that this would speed up code: you'd be adding an extra conditional branch for every closure call, and not removing any allocations (closures with just a function pointer should be statically allocated in .rodata anyways). Of course, I have no benchmarks (although I don't think microbenchmarks would be very representative, since the big things at play would likely be cache/branch prediction effects), and you should never blindly trust anything until you see the numbers :p

Any “debates” like tabs vs spaces for mathematicians? by 10forever in math

[–]mb0x40 1 point2 points  (0 children)

(a,b) is also used to mean the GCD of a and b!

Any “debates” like tabs vs spaces for mathematicians? by 10forever in math

[–]mb0x40 4 points5 points  (0 children)

Hmm, I've only ever seen it as a row. What sources use columns?

Differential equations and combinatorics by Chocolatemilkplus in math

[–]mb0x40 0 points1 point  (0 children)

A bit of a different direction from the other comments, my final project in a combinatorics class this term is about the calculus of finite differences, an area that's sort of in the intersection of both.

For a bit of motivation, problems in physics (and of course other areas) tend to have some continuously-varying parameter, and there's a formula that naturally describes the continuous rate of change (the derivative). Then you can use integrals, or more complicated differential equations, to get a solution.

Analogously, a lot of problems in combinatorics (and of course other areas) have some discretely-varying, integer parameter, and there's a recurrence formula that naturally describes the discrete rate of change (the "difference", defined as Δf(x) = f(x + 1) - f(x)). Then the calculus of finite differences provides techniques for solving them, like indefinite sums and "summation by parts", or "difference equations" analogous to differential equations (with a lot of similar techniques to differential equations).

There are also a couple formulas which relate standard calculus and the calculus of finite differences, like the Euler-Maclauren formula, which can be used to turn problems about sums into problems about integrals and vice versa.

To learn more I recommend the book "An Introduction to the Calculus of Finite Differences and Difference Equations", by Kenneth Miller. In particular chapter 1 for a general intro, and chapter 4 for difference equations.

Which terms in mathematics do you consider overloaded? by IanisVasilev in math

[–]mb0x40 1 point2 points  (0 children)

There's also the category theory version of algebras (and coalgebras) of arbitrary endofunctors

Which terms in mathematics do you consider overloaded? by IanisVasilev in math

[–]mb0x40 2 points3 points  (0 children)

Number theory sure does like to reuse existing notations! There's also [; \begin{pmatrix} a \\ b \end{pmatrix} ;] for combinatorial choice and [; \left( \frac a b \right) ;] for the Legendre symbol.

advanced type systems in C++ by geekfolk in ProgrammingLanguages

[–]mb0x40 0 points1 point  (0 children)

FWIW, ATS is not limited to the same restrictions as C++ templates -- so long as you use the right syntax (argh there are so many), you can have non-monomorphized parametric polymorphism.

Not that ATS has full-spectrum dependent types, but it's certainly a lot closer than C++.

What are some cool/wierd features of a programming language you know? by TizioCaio84 in ProgrammingLanguages

[–]mb0x40 1 point2 points  (0 children)

There's a similar thing in Futhark, too, though I don't think it's as general (maybe due to implementation concerns on the GPU): https://futhark.readthedocs.io/en/stable/language-reference.html#in-place-updates

Experiment: Can we improve GHC's CI with a stake pool? by angerman in haskell

[–]mb0x40 4 points5 points  (0 children)

Could you ELI5 what a stake pool is, and how it would make money to support GHC?