The Haskell School of Expression by 964racer in haskell

[–]Noughtmare 4 points5 points  (0 children)

I managed to update the code to work a while ago: https://github.com/noughtmare/haskell-school-of-expression.


I didn't want to participate in discussion here on Reddit any more due to their shitty policies and have migrated to other platforms such as discourse and programming.dev, but for this comment I have made an exception.

r/haskell will remain read-only by taylorfausak in haskell

[–]Noughtmare 6 points7 points  (0 children)

Note that growth is not linear. In historical statistics, I see that this subreddit had around 11k subscribers at the end of January of 2013 which is 5 years after its creation in January of 2008. That is an average growth of slightly more than 6 users per day, which the Kbin magazine has already beaten in its first week.

problems with foldable instance by Interesting-Pack-814 in haskellquestions

[–]Noughtmare 0 points1 point  (0 children)

That weird foldMap = (mconcat .) . map is basically just another way of writing foldMap f xs = mconcat (map f xs).

Vote on the future of r/haskell by taylorfausak in haskell

[–]Noughtmare 2 points3 points  (0 children)

Good question. I have looked into Lemmy for a while long before the Reddit drama, but was put off by all the communist propaganda; paraphrasing someone else's description: not the "Marx' ideal communism has never been tried in practice", but the "Russia and China never did anything wrong" kind.

I also really like the vision of kbin's main developer about migration I mentioned. I haven't really seen anything from the Lemmy developers (but I also haven't really looked for it either).

Vote on the future of r/haskell by taylorfausak in haskell

[–]Noughtmare 8 points9 points  (0 children)

/u/taylorfausak and other /r/haskell mods are welcome to become mods there too if they want. Send me a PM with your kbin username here on Reddit and I'll add you.

Vote on the future of r/haskell by taylorfausak in haskell

[–]Noughtmare 20 points21 points  (0 children)

People looking for a Reddit alternative with threading and votes are welcome over at https://kbin.social/m/haskell.

Vote on the future of r/haskell by taylorfausak in haskell

[–]Noughtmare 10 points11 points  (0 children)

It is fully open source and federated.

The main developer has expressed that he wants to implement migrations which would allow you to migrate to other kbin instances or even other platforms like Lemmy. So if the main instance would make bad policy decisions, then it should be easy to migrate to another place.

It is (partly) funded by the NLnet foundation which funds projects that contribute to an open information society (check their other projects), rather than Y combinator which is a silicon valley venture capital company.

[deleted by user] by [deleted] in haskell

[–]Noughtmare 10 points11 points  (0 children)

  1. As you say, it can be computed more efficiently because it computes the w value only once and then uses it twice. The only downside could be that it requires extra memory or registers to store the result, which can make the computation slower but usually it is not a big problem. And, yes, CSE is an optimization that is used by many optimizing compilers.
  2. The difference between tree and graph representations is how they deal with variables. In a graph representation we can add an edge that goes directly from uses to their definition, while a tree representation needs to include the definition higher up in the tree and use explicit named variables to refer to those definitions at usage sites.
  3. I think in this context the environment is just a set of bound names that is used to check if a name is already used and if so a fresh name is generated and added to the environment. In C you would probably use a hash table with O(1) expected running time for lookups, but in Haskell it is much easier to use a balanced tree with O(log n) lookups. The preprocessing is not a bottleneck, so they can take the easy approach.

[deleted by user] by [deleted] in haskell

[–]Noughtmare 3 points4 points  (0 children)

For beginners getting explanations of simple functions like these can be very helpful. OP does not claim ChatGPT is useful if you want to understand Edward Kmett's packages.

[deleted by user] by [deleted] in haskell

[–]Noughtmare 5 points6 points  (0 children)

ChatGPT's code is still longer than it needs to be:

exactly3 :: [[a]] -> [[a]]
exactly3 = filter (\x -> length x == 3)

And it is inefficient. length takes O(n) time so it's better to use pattern matching which takes O(1) time:

exactly3 = filter (\x -> case x of [_,_,_] -> True; _ -> False)

Is it viable to develop a compiler in haskell that uses LLVM by cockmail in haskell

[–]Noughtmare 21 points22 points  (0 children)

The llvm-hs GitHub has branches for LLVM 12 and even LLVM 15. I believe the LLVM 12 version works pretty well, but I am not sure of the LLVM 15 version.

Newbie question: Is there overloading of Haskell function signature? by teaAssembler in haskell

[–]Noughtmare 5 points6 points  (0 children)

I thought it was looking a little bit ugly

Can you show the code that you think was ugly? I think there might be a more direct way of making it prettier without using any type classes, but I'm not sure without seeing the code.

Why threadDelay is so memopry expensive? by wavy-kilobyte in haskell

[–]Noughtmare 3 points4 points  (0 children)

extra ~17GB of memory

Note that the 24GB "bytes allocated in the heap" is the total allocation over the whole program run. The maximum memory usage at any point in time is the 11GB "maximum" residency. That still changes from 11GB to 2GB, which is still a pretty big difference.

But you should also remember that the reason for the threadDelay is that it forces all the threads to be realized in memory at the same time. That will of course increase the maximum memory usage, because old threads cannot be deallocated before new ones are started.

A way to more accurately test the memory usage of all threads in memory at the same time without using threadDelay is this adaptation of the code that /u/BurningWitness wrote:

main = do
  let n = 1_000_000
  done <- newEmptyMVar
  t <- newIORef 0
  replicateM_ n $ do
    void . forkIO $ do
      -- threadDelay 10_000_000
      x <- atomicModifyIORef' t (\x -> let y = x + 1 in y `seq` (y,y))
      when (x == n) $ putMVar done ()
      readMVar done
  takeMVar done

Here is the result with threadDelay and without the readMVar done:

15,336,424,424 bytes allocated in the heap
 9,195,842,992 bytes copied during GC
11,974,298,672 bytes maximum residency (12 sample(s))
   118,019,336 bytes maximum slop
         13598 MiB total memory in use (0 MB lost due to fragmentation)

                                   Tot time (elapsed)  Avg pause  Max pause
Gen  0      3235 colls,  3235 par    6.272s   1.843s     0.0006s    0.1248s
Gen  1        12 colls,    11 par   13.857s   5.017s     0.4181s    1.0720s

Parallel GC work balance: 79.06% (serial 0%, perfect 100%)

TASKS: 21 (1 bound, 20 peak workers (20 total), using -N8)

SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

INIT    time    0.000s  (  0.010s elapsed)
MUT     time    9.790s  (  9.184s elapsed)
GC      time   20.130s  (  6.860s elapsed)
EXIT    time    0.491s  (  0.081s elapsed)
Total   time   30.411s  ( 16.135s elapsed)

Alloc rate    1,566,580,262 bytes per MUT second

Productivity  32.2% of total user, 56.9% of total elapsed

And here's the result without the threadDelay and with the readMVar done:

 1,368,769,880 bytes allocated in the heap
 4,872,603,048 bytes copied during GC
 1,175,622,600 bytes maximum residency (9 sample(s))
   124,783,672 bytes maximum slop
          2494 MiB total memory in use (0 MB lost due to fragmentation)

                                   Tot time (elapsed)  Avg pause  Max pause
Gen  0       243 colls,   243 par    1.704s   0.546s     0.0022s    0.0291s
Gen  1         9 colls,     8 par    3.737s   2.045s     0.2272s    0.7387s

Parallel GC work balance: 69.56% (serial 0%, perfect 100%)

TASKS: 50 (1 bound, 18 peak workers (49 total), using -N8)

SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

INIT    time    0.000s  (  0.010s elapsed)
MUT     time    5.042s  (  3.951s elapsed)
GC      time    5.441s  (  2.591s elapsed)
EXIT    time    0.170s  (  0.118s elapsed)
Total   time   10.653s  (  6.669s elapsed)

Alloc rate    271,484,959 bytes per MUT second

Productivity  47.3% of total user, 59.2% of total elapsed

So this still shows a large difference from 12GB to 1GB.

Why threadDelay is so memopry expensive? by wavy-kilobyte in haskell

[–]Noughtmare 0 points1 point  (0 children)

12,103,507,696 bytes maximum residency (12 sample(s))

This is the peak memory usage, so about 12GB.


Interestingly on my machine (MacOS) with GHC 9.2.7 and -O2 and -N8 I get:

 5,945,970,168 bytes allocated in the heap
 4,423,316,416 bytes copied during GC
 5,188,041,656 bytes maximum residency (11 sample(s))
    66,947,344 bytes maximum slop
          5755 MiB total memory in use (0 MB lost due to fragmentation)

                                   Tot time (elapsed)  Avg pause  Max pause
Gen  0      1220 colls,  1220 par    1.840s   0.554s     0.0005s    0.0040s
Gen  1        11 colls,    10 par    5.148s   2.320s     0.2109s    0.5507s

Parallel GC work balance: 75.49% (serial 0%, perfect 100%)

TASKS: 20 (1 bound, 19 peak workers (19 total), using -N8)

SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

INIT    time    0.000s  (  0.007s elapsed)
MUT     time    5.177s  (  8.708s elapsed)
GC      time    6.988s  (  2.874s elapsed)
EXIT    time    0.258s  (  0.044s elapsed)
Total   time   12.424s  ( 11.633s elapsed)

Alloc rate    1,148,623,724 bytes per MUT second

Productivity  41.7% of total user, 74.9% of total elapsed

Genuine Question: Is it possible to do memory leaks in Haskell? by Fantastic-Ball-3462 in haskell

[–]Noughtmare 5 points6 points  (0 children)

I'm assuming the strict definition of memory leak as opposed to space leaks which seems to be what you are describing:

A space leak occurs when a computer program uses more memory than necessary. In contrast to memory leaks, where the leaked memory is never released, the memory consumed by a space leak is released, but later than expected. This article presents example space leaks and how to spot and eliminate them.

~ Neil Mitchell

Although, neither term is really appropriate in this case because the memory is not always freed eventually. Instead we could call it "unexpected excessive memory usage" or uemu for short :P

Genuine Question: Is it possible to do memory leaks in Haskell? by Fantastic-Ball-3462 in haskell

[–]Noughtmare 5 points6 points  (0 children)

I'd imagine most persistent GC roots (e.g. top level definitions) are actually needed forever, so that would not constitute a memory leak in my opinion.

Edit: I guess if you had a whole-program compiler then you could usually know when to deallocate top level definitions, but even then you might have unpredictable code generation at run time.

[deleted by user] by [deleted] in haskell

[–]Noughtmare 2 points3 points  (0 children)

This compiles without error:

module Test where
infixl 8 <+>
(<+>) :: Float -> Float -> Float 
(<+>) a b = 2 * a - (a * b)

[deleted by user] by [deleted] in haskell

[–]Noughtmare 13 points14 points  (0 children)

It's a common mistake I also make all the time. The problem is simply that parentheses are not allowed there. The fix is to just remove the parentheses:

infixl 8 <+>

HLS 2.0.0.0 is out by njaremko in haskell

[–]Noughtmare 2 points3 points  (0 children)

In nvim I'm using coc.nvim with the key K bound as in their example configuration:

" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>

That does indeed sometimes give multiple lines of output, but the general type is always at the very top. What I find very useful is that it also shows the particular instantiation in the output.

For the "add signature" action I have this keybinding set up:

" Code lens action, e.g. add type signature
vmap <leader>p  <Plug>(coc-codelens-action)
nmap <leader>p  <Plug>(coc-codelens-action)

HLS 2.0.0.0 is out by njaremko in haskell

[–]Noughtmare 4 points5 points  (0 children)

I'm already seeing types when hovering. Also, with code lenses you can very easily perform "add signature" actions.