Haskell

brokenix,

pseq combinator is used for sequencing; informally, it eval-
uates its first argument to weak-head normal form, and then eval-
uates its second argument, returning the value of its second argu-
ment. Consider this definition of parMap:
parMap f [] = []
parMap f (x:xs) = y ‘par‘ (ys ‘pseq‘ y:ys)
where y = f x
ys = parMap f xs
The intention here is to spark the evaluation of f x, and then
evaluate parMap f xs, before returning the new list y:ys. The
programmer is hoping to express an ordering of the evaluation: first
spark y, then evaluate ys.
The obvious question is this: why not use ’s built-in seq
operator instead of pseq? The only guarantee made by seq is that
it is strict in both arguments; that is, seq a ⊥ = ⊥ and seq ⊥
a = ⊥. But this semantic property makes no operational guaran-
tee about order of evaluation. An implementation could impose this
operational guarantee on seq, but that turns out to limit the optimi-
sations that can be applied when the programmer only cares about
the semantic behaviour. Instead, we provide both pseq and seq
(with and without an order-of-evaluation guarantee), to allow the
programmer to say what she wants while leaving the compiler with
as much scope for optimisation as possible.
https://simonmar.github.io/bib/papers/multicore-ghc.pdf

sgraf,
@sgraf@mastodon.online avatar

@brokenix ironically, the implementation of pseq is broken today https://gitlab.haskell.org/ghc/ghc/-/issues/23233 and probably has been broken since inception

maralorn, (edited )
@maralorn@chaos.social avatar

After extensively using the library for half a year at work I have now played around with the library again. I am amazed by how much more helpful error messages are with . It’s an amazing library and I would recommend it over whenever you have the choice.

maralorn,
@maralorn@chaos.social avatar

@mangoiv Hasn’t been my impression with yet. To me it feels like the type level stuff is "finished". As long as you only define and use existing types of optics you don’t need to worry about it.

mangoiv,
@mangoiv@functional.cafe avatar

@maralorn sounds really good! I think I might actually wanna try them at work.

kosmikus,
@kosmikus@functional.cafe avatar

It's finally time for the next episode of the #Haskell #Unfolder. In episode 23, my colleagues Finley, Edsko, and I will discuss the topic of "specialisation", an important GHC optimisation that can help eliminate the cost intrinsic to overloaded functions. This will be streamed live on YouTube, on Tuesday, 2024-04-16, at 1830 UTC. https://www.youtube.com/watch?v=ksW04Cl2dgo&list=PLD8gywOEY4HaG5VSrKVnHxCptlJv2GAn7&index=23

sellout,
@sellout@mastodon.social avatar

I made a thing in case you were starting to think programming is too easy.

https://github.com/sellout/no-recursion – a plugin to remove support from

(I have multiple use cases for this, I swear.)

sellout,
@sellout@mastodon.social avatar

@boarders This is one of my use cases. The great thing about recursion schemes is that they don’t require recursion. And all streaming can be done with recursion schemes, so also no recursion.

But currently it’s pretty basic. You can use recursive functions from other modules … as long as they don’t get inlined. And there’s no way to restrict imported recursive functions. But please, open issues with stuff you’d like to see.

boarders,
@boarders@mathstodon.xyz avatar

@sellout ah fantastic, I want the same thing (I actually wanted it as a language extension similar to explicitly letrec, but dont currently have faith in the language proposal process as it attracts a lot of lawyer types)

For the guarded recursion thing, I had in mind coinductive programming which can be done with recursion schemes for coalgebra or with have an explicit tick operator as in guarded type theory / agda

6d03,
@6d03@mathstodon.xyz avatar

I remember recently reading a new paper elaborating a novel presentation of graph algebras. But I can't for the life of me remember the title or the author.

The central idea was axiomatizing vertices as pairs of sets of all incoming and outgoing edges.

It also had example code in Haskell.

Does anybody have an idea of the title? I'd be very thankful for suggestions.

victor_tokarev,
@victor_tokarev@twiukraine.com avatar
6d03,
@6d03@mathstodon.xyz avatar

@victor_tokarev that's the one. thank you very much.

jaror,
jaror avatar

Declarative vs imperative:

let v = sum [ ((x ! i) - m) ^ 2 | i <- [0 .. cc - 1] ] / fromIntegral cc
float v = 0.0f;
for (int i = 0; i < C; i++) {
    float xshift = x[i] - m;
    v += xshift * xshift;
}
v = v/C;
jaror,
jaror avatar

Admittedly it gets more complicated when summing two things at the same time:

let Pair dnormMean dnormNormMean = 
      fold (Pair <$> dimap (\(Pair _ dnormI) -> dnormI) (/ fromIntegral cc) sum
                 <*> dimap (\(Pair normBti dnormI) -> normBti * dnormI) (/ fromIntegral cc) sum)
        $ map (\i -> Pair (((inp ! (off + i)) - meanBt) * rstdBt)
                          ((weight ! i) * (dout ! (off + i))))
          [0 .. cc - 1]
float dnorm_mean = 0.0f;
float dnorm_norm_mean = 0.0f;
for (int i = 0; i < C; i++) {
    float norm_bti = (inp_bt[i] - mean_bt) * rstd_bt;
    float dnorm_i = weight[i] * dout_bt[i];
    dnorm_mean += dnorm_i;
    dnorm_norm_mean += dnorm_i * norm_bti;
}
dnorm_mean = dnorm_mean / C;
dnorm_norm_mean = dnorm_norm_mean / C;
someodd,
@someodd@fosstodon.org avatar

Please share with me your wisdom on packaging and distributing software made with .

simonmic,
@simonmic@fosstodon.org avatar

@someodd, here's a few thoughts on #haskell packaging/distribution:

  • Support the widest range of GHC versions, deps, and all related tools you can reasonably manage, reducing unnecessary friction.

  • Get your packages and their dependencies into Stackage nightly and keep them there. From there they will trickle into Stackage LTS, which is a starting point for many packaging systems.

1/

simonmic,
@simonmic@fosstodon.org avatar
  • When you need to provide assets other than the executable, embed them eg with file-embed. The file lookup mechanism provided by Cabal is too fragile.

  • When you want to be cross platform: check your deps, avoid unix-only packages, avoid packages that require external C libs if possible.

2/
#haskell

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

When building Servant applications with persistence, a common (?) pattern is to request a database connection from a pool in the callback we pass to "hoistServer" https://hackage.haskell.org/package/servant-server-0.20/docs/Servant-Server.html#v:hoistServer and then pass the connection down to the handler using ReaderT https://github.com/danidiaz/comments-project/blob/3bb720124b31f0a8e351751bdcc6651ed75d9e27/comments/lib/Comments/Runner.hs#L57
It works, but I'm kinda unhappy about it because it forces you to use ReaderT in those intermediate components that lie between the top-level handler and the repository component which actually uses the connection. 😕

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

You might say "Well, that's not a problem, just make those intermediate components that don't care about the connection polymorphic over MonadUnliftIO! Later, when composing the application, they will be injected a repository that does know about the ReaderT and the connection. Problem solved."

That's true, but what if I wanted those intermediate components to be as dumb as possible? Just plain records of functions in IO, no monad transformers, and no polymorphism over the monad, either?

DiazCarrete, (edited )
@DiazCarrete@hachyderm.io avatar

"I got rid of ReaderT and now my application is hanging by a thread"
https://discourse.haskell.org/t/i-got-rid-of-readert-and-now-my-application-is-hanging-by-a-thread/9330

leanpub,
@leanpub@mastodon.social avatar

Finding Success (and Failure) in Haskell by Type Classes is on sale on Leanpub! Its suggested price is $35.00; get it for $12.50 with this coupon: https://leanpub.com/sh/4sG8LBPo

kosmikus,
@kosmikus@functional.cafe avatar

At Well-Typed, we are currently looking for a new #Haskell developer (possibly more) to join our team: https://well-typed.com/blog/2024/04/haskell-development-job-with-well-typed/

nmeum,
@nmeum@chaos.social avatar

Here is a preprint of fun paper that I've been working on which investigates the utilization of formal descriptions of instruction semantics to perform symbolic binary-level program analysis: https://doi.org/10.48550/arXiv.2404.04132

It includes a prototype implementation in Haskell which performs symbolic execution of RISC-V binary code without requiring the transformation to an intermediate representation (like LLVM IR).

nmeum,
@nmeum@chaos.social avatar

This paper also includes an empirical comparison with prior work which I attempted to design in a reproducible way by using for the evaluation artifacts: https://doi.org/10.5281/zenodo.10925791

nmeum,
@nmeum@chaos.social avatar

The latest and greatest GHC version (9.8.2) is now available in the Alpine Linux Edge repositories and will be included in the upcoming 3.20 stable release.

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

Rel8 is a library that teeters between "looking at the instances provides much useful information" and "looking at the instances causes psychic damage".
https://hackage.haskell.org/package/rel8-1.5.0.0/docs/Rel8.html#t:Table

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

Relatedly, it would be a nice feature for Haddock if the instances local to a module could be sorted and grouped for the purposes of documentation and telling a story.

Like "These are the instances for tuples of various sizes" or "this is the base case and these are some instances that recurse".

DiazCarrete,
@DiazCarrete@hachyderm.io avatar
someodd,
@someodd@fosstodon.org avatar

Is there any future in languages like where AI makes code a factor of small frequently and easily replaced glue and scraps, where whatever is most trained on and most hackable, most easily replaced/iterable is king?

Are big pieces of software that benefit from the architectural assurances Haskell brings a dead paradigm?

AI is here to stay and I feel if something was not already in or out of orbit, it may never reach escape velocity

haskell_foundation,
@haskell_foundation@mastodon.social avatar

effectfully describes as a beautiful and amazing language. In episode 46 of , Wouter Swierstra and Joachim Breitner asked effectfully about how he found a new passion for programming. Listen to the episode here: https://haskell.foundation/podcast/46/

  • All
  • Subscribed
  • Moderated
  • Favorites
  • haskell
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • khanakhh
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • cubers
  • GTA5RPClips
  • cisconetworking
  • ethstaker
  • osvaldo12
  • modclub
  • normalnudes
  • provamag3
  • tester
  • anitta
  • Leos
  • megavids
  • lostlight
  • All magazines