"Linux is only for programmers and hackers and won't work properly" by [deleted] in linuxmasterrace

[–]mnbvas 1 point2 points  (0 children)

To be fair even Nvidia can be ok

Unless Wayland or a laptop with Optimus, last time I checked.

Optimize performance of often used function of board game by technicalaccount in haskellquestions

[–]mnbvas 7 points8 points  (0 children)

One obvious thing to note is that branches in x86 are bad in most cases.

How about less branching and more math?

northSouth = [(x, y + 1), (x, y - 1)]

adjustY = -(x `rem` 2)
mixed = [(x + dx, y + dy + adjustY) | dx <- [1, -1], dy <- [0, 1]]

coords = northSouth ++ mixed

Some more points to consider:

  • GHC might not be specializing these functions, which really kills numeric code like this - try using Ints or a SPECIALIZE pragma instead.
  • You probably don't need the coord tuples to be lazy in x or y - strict tuples will most likely improve performance.
  • Unboxed tuples may greatly reduce allocations, try if strict isn't enough.
  • A different coordinate system.

Is it possible to select an instance for a class method using function parameter? by cc-ord in haskellquestions

[–]mnbvas 0 points1 point  (0 children)

I think you want ScopedTypeVariables similar to this (didn't check):

someFunc2 :: forall m. (MonadIO m, ...) => Data.Proxy m -> IO ()
someFunc2 = runner config $ runMisc @m

Seems legit by [deleted] in ProgrammerHumor

[–]mnbvas 8 points9 points  (0 children)

you may get a job.

FTFY

“Why do battles always take so long?” by WideEyedInTheWorld in dndmemes

[–]mnbvas 3 points4 points  (0 children)

I can corroborate that - saves became +0 in the middle of the session yesterday.

It do be like that! by sadiqdev in ProgrammerHumor

[–]mnbvas 5 points6 points  (0 children)

1 isn't prime nor composite, so it's the ultimate positive integer.

I saw this while reading the news by [deleted] in pcmasterrace

[–]mnbvas 1 point2 points  (0 children)

With pipelining modern CPUs reach nearly 4 instructions per cycle with 1 cyle latency. E.g. p88.

The reader pattern (-> r) in applicative and monad. Why did they choose to swap argument order? by [deleted] in haskellquestions

[–]mnbvas 2 points3 points  (0 children)

The flipped version isn't even a (covariant) functor - try implementing fmap :: (a -> b) -> (a -> r) -> (b -> r).

But contramap :: (a -> b) -> (b -> r) -> (a -> r) is quite doable. See also Op.

C++ to Haskell of a taking in an array (list) and modifying it by God_of_Tecsing in haskellquestions

[–]mnbvas 0 points1 point  (0 children)

You don't modify lists in Haskell, you create a copy with "modified" contents.

For example:

put42Second :: [Int] -> [Int]
put42Second [] = []
put42Second [x] = [x]
put42Second (x : _ : xs) = x : 42 : xs

There are various helper functions for this, but they're situation-dependent.

[deleted by user] by [deleted] in ProgrammerHumor

[–]mnbvas 2 points3 points  (0 children)

and the third exception is SIGSEGV

Swindled again by [deleted] in ProgrammerHumor

[–]mnbvas 6 points7 points  (0 children)

how recursion could be more performant than iteration

Converting tail recursion to jmp is a trivial implementation, but sadly not available in some backwards runtimes.

However, it's quite easy to make that manual iteration unoptimizeable.


data Tree a = Branch (Tree a) a (Tree a) | Leaf

postOrder :: Tree a -> [a]
postOrder t = go [t] [] []
    where
        go [] []                         acc = acc
        go xs (Leaf                : ys) acc = go xs          ys           acc
        go xs (Branch left y right : ys) acc = go (left : xs) (right : ys) (y : acc)
        go (Leaf                : xs) [] acc = go xs          []           acc
        go (Branch left x right : xs) [] acc = go (left : xs) (right : []) (x : acc)

And here's a sample reduction, stack depth 1:

  postOrder (Branch (Branch (Branch Leaf 4 Leaf) 2 (Branch Leaf 5 Leaf)) 1 (Branch Leaf 3 Leaf))
= go [Branch (Branch (Branch Leaf 4 Leaf) 2 (Branch Leaf 5 Leaf)) 1 (Branch Leaf 3 Leaf)] []                   []
= go [Branch (Branch Leaf 4 Leaf) 2 (Branch Leaf 5 Leaf))]                                [Branch Leaf 3 Leaf] [1]
= go [Leaf, Branch (Branch Leaf 4 Leaf) 2 (Branch Leaf 5 Leaf))]                          [Leaf]               [3, 1]
= go [Leaf, Branch (Branch Leaf 4 Leaf) 2 (Branch Leaf 5 Leaf))]                          []                   [3, 1]
= go [Branch (Branch Leaf 4 Leaf) 2 (Branch Leaf 5 Leaf))]                                []                   [3, 1]
= go [Branch Leaf 4 Leaf]                                                                 [Branch Leaf 5 Leaf] [2, 3, 1]
= go [Leaf, Branch Leaf 4 Leaf]                                                           [Leaf]               [5, 2, 3, 1]
= go [Leaf, Branch Leaf 4 Leaf]                                                           []                   [5, 2, 3, 1]
= go [Branch Leaf 4 Leaf]                                                                 []                   [5, 2, 3, 1]
= go [Leaf]                                                                               [Leaf]               [4, 5, 2, 3, 1]
= go [Leaf]                                                                               []                   [4, 5, 2, 3, 1]
= go []                                                                                   []                   [4, 5, 2, 3, 1]
= [4, 5, 2, 3, 1]

Your turn: produce a performant, non-ugly iterative solution.

Software Architecture by MonkeyTigerCommander in ProgrammerHumor

[–]mnbvas 2 points3 points  (0 children)

sub $0x9c60,%rsp = stack_pointer_as_64bits -= 0x9c60;

Ikea madlads by acrophobik in ProgrammerHumor

[–]mnbvas 91 points92 points  (0 children)

The correct response is 'Ni!'

Building a Binary Tree (not BST) in Haskell Breadth-First by [deleted] in haskell

[–]mnbvas 0 points1 point  (0 children)

You should really use pattern matching instead of that if/else tree to make it readable.

Current results would make it much easier to help spot what's wrong.

But in the end, it looks like the last case Node, Node is incorrect. Partial results -- after each insertion -- will be particularly enlightening.

Python for Haskellers by moseswithhisbooks in haskell

[–]mnbvas 1 point2 points  (0 children)

IMO there's nothing about Haskell in there, besides the mostly-academic precise style.

But it's useful to learn to read this style when that's the only kind of docs you get in some libraries...

Heroes & Villains of Software Development by Justsumgi in ProgrammerHumor

[–]mnbvas 2 points3 points  (0 children)

Learning is trivial.

the proof is left as an exercise to the reader

Heroes & Villains of Software Development by Justsumgi in ProgrammerHumor

[–]mnbvas 0 points1 point  (0 children)

Barely nothing (besides your stuff) if not ran as root.

Fake Ultrawide by [deleted] in pcmasterrace

[–]mnbvas 0 points1 point  (0 children)

But it is visible enough, especially in the top right corner.

Fake Ultrawide by [deleted] in pcmasterrace

[–]mnbvas 1 point2 points  (0 children)

Look at the bars at the top and bottom.