jaror avatar

jaror

@jaror@kbin.social

All the side effects were never mentioned to me
I am innocent of uncontrolled abuse

[Well-Typed Blog] Improvements to the ghc-debug terminal interface (www.well-typed.com)

ghc-debug is a debugging tool for performing precise heap analysis of Haskell programs (check out our previous post introducing it). While working on Eras Profiling, we took the opportunity to make some much needed improvements and quality of life fixes to both the ghc-debug library and the...

[Well-Typed Blog] Choreographing a dance with the GHC specializer (Part 1) (well-typed.com)

This is the first of a two-part series of blog posts on GHC specialization, an optimization technique used by GHC to eliminate the performance overhead of ad-hoc polymorphism and enable other powerful optimizations. There will also be a Haskell Unfolder episode about this topic.

jaror,
jaror avatar

Stream fusion does work:

data Stream a = forall s. Stream !(s -> Step s a) !s
data Step s a = Yield a !s | Skip !s | Done

data Tup a b = Tup !a !b

cartesianProduct :: Stream a -> Stream b -> Stream (a, b)
cartesianProduct (Stream step1 s01) (Stream step2 s02) = Stream step' s' where
  s' = Tup s01 s02
  step' (Tup s1 s2) =
    case step1 s1 of
      Yield x s1' ->
        case step2 s2 of
          Yield y s2' -> Yield (x, y) (Tup s1 s2')
          Skip s2' -> Skip (Tup s1 s2')
          Done -> Skip (Tup s1' s02)
      Skip s1' -> Skip (Tup s1' s2)
      Done -> Done

eft :: Int -> Int -> Stream Int
eft x y = Stream step x where
  step s
    | s > y = Done
    | otherwise = Yield s (s + 1)

fooS :: Stream (Int, Int)
fooS = cartesianProduct (eft 0 10) (eft 0 10)

toList :: Stream a -> [a]
toList (Stream step s0) = go s0 where
  go !s =
    case step s of
      Yield x s' -> x : go s'
      Skip s' -> go s'
      Done -> []

foo :: [(Int,Int)]
foo = toList fooS
jaror, to haskell
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, to haskell
@someodd@fosstodon.org avatar

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

jaror,
jaror avatar

@someodd Also note that the advice is about Stackage and not Stack. You can use Stackage snapshots with Cabal. E.g. you can create a cabal.project file with a line like this: import: https://www.stackage.org/lts-22.16/cabal.config. It still has a lot of rough edges, for example it is not possible to override specific constraints from the snapshots, but it is usable.

@simonmic

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar
jaror,
jaror avatar

@DiazCarrete That slide seems to misrepresent effect systems. It is easy to replace just runInputConst:

runAllEffects (runInputDifferently program)

The runInputDifferently effect handles the Input Config effect and it leaves an unused Input Config in the list of effects. So the runInputConst config handler in runAllEffects will not be used.

someodd, to haskell
@someodd@fosstodon.org avatar

Could I get some love, please?

I feel I'm developing lots of software in for and cool things.

A showcase of some of my projects: https://www.someodd.com/showcase

My GitHub (please follow, star): https://github.com/someodd

jaror,
jaror avatar

@someodd Your showcase website times out for me.

jaror,
jaror avatar

@someodd That page loads instantly.

jaror,
jaror avatar

@someodd I see it is just the .com domain that is problematic. The https://www.someodd.zip/showcase does load fine.

jaror,
jaror avatar

@someodd Yeah, I think kbin.social doesn't federate edits yet.

mangoiv, (edited ) to haskell
@mangoiv@functional.cafe avatar

Is it just me or is this whole thing about „don’t do X if you don’t really know what you’re doing“ really counter productive? Many people live in fear of X now and don’t start thinking if X is an actual problem or learn what the problems are that could rise from X.

I see this very often in the ecosystem where the solution to doing X properly is often learnt in a few minutes investigation.

jaror,
jaror avatar

@mangoiv I know I've said that a few times. Two examples I can think of:

  • AllowAmbiguousTypes, GHC suggests this but you should probably just use Proxy arguments instead.
  • Typeable, people coming from OOP languages often want a typeof function, but 99% of the time there is a better way to structure your programs using simple ADTs.

I still think these are not learnt in a few minutes. Even if that was the case, the most important thing you should learn is that you shouldn't use them very often.

pmidden, to haskell
@pmidden@fosstodon.org avatar

TIL about MicroHs, an alternative compiler that can compile Haskell2010 https://hackage.haskell.org/package/MicroHs-0.9.8.0

jaror,
jaror avatar

@pmidden There's also a recording of Lennart Augustsson talking about how and why he made it: https://www.youtube.com/watch?v=Zk5SJ79nOnA

Simple Programming Languages (ryanbrewer.dev)

In this post I want to make this kind of simplicity more precise and talk about some reasons it’s important. I propose five key ideas for simple programming languages: ready-at-hand features, fast iteration cycles, a single way of doing things, first-order reasoning principles, and simple static type systems. I discuss each of...

jaror,
jaror avatar

The machine itself can generally only do very simple things

I disagree. Assembly languages for modern architectures are a complexity hell. You need books with thousands of pages to explain how they work. In comparison the lambda calculus is much simpler.

The Haskell Unfolder Episode 22: foldr-build fusion (well-typed.com)

When composing several list-processing functions, GHC employs an optimisation called foldr-build fusion. Fusion combines functions in such a way that any intermediate lists can often be eliminated completely. In this episode, we will look at how this optimisation works, and at how it is implemented in GHC: not as built-in...

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