Formerly u/CanadaPlus101 on Reddit.

  • 38 Posts
Joined 11 months ago
Cake day: June 12th, 2023


  • Uh, let’s look at my GHCi history…

    It looks like I was last searching for 12-member sets of permutations of 7 which come close to generating every possible permutation of seven elements, as well as meeting a few other criteria, for an electronics project. It ended up being more like 10 lines plus comments, though, plus a big table generated by GAP, which I formatted into a Haskell list using probably a line of Haskell plus file loading.

    Unfortunately for providing code, me playing with the finished algorithm has eaten up my whole 100 lines of history. So, here’s a two-liner I posted on Lemmy before, that implements a feed-forward neural net. It’s not exactly what you asked for, but it gives you an idea.

    layer layerInput layerWeights = map relu $ map sum $ map (zipWith (*) layerInput) layerWeights
    foldl layer modelInput modelWeights

    In practice, you might also need to define relu in another line:

    relu x = if x > 0 then x else 0

    Edit: No wait, I think that was a different problem related to the same project. There’s another module attached that generates all permutations of n items. After breaking it up so it’s a bit less write-only:

    allPermutations :: Int -> [[Int]]
    allPermutations 1 = [[0]]
    allPermutations n = concat $ map (addItem $ allPermutations (n-1) ) [0..(n-1)]
    addItem :: [[Int]]  -> Int -> [[Int]]
    addItem old new = map (\y -> new : map (fitAround new) y) old
    fitAround :: Int -> Int -> Int
    fitAround n y
    	| y >= n	= y+1
    	| otherwise	= y

  • It’s been noted that functional code accumulates less bugs, because there’s no way to accidentally change something important somewhere else, and Haskell is the standard for functional languages. Also, it might just be me, but the type system also feels perfect when I use it. Like, my math intuition says there’s no better way to describe a function; it’s showing the logic to me directly.

    Where Haskell is weak is when interactivity - either with the real world or with other components - comes up. You can do it, but it really feels like you’re writing normal imperative code, and then just squirreling it away in a monad. It’s also slower than the mid-level languages. That being said, if I need to quickly generate some data, Haskell is my no-questions go to. Usually I can do it in one or two lines.

  • The year was built around it, not the other way. It’s all derived from the Christian calendar. I’m not sure off the top of my head how Christmas ended up a few days before New Years, but they’re deliberately very close. It has been argued that the real life birth might not have been in winter at all (or even Bethlehem).

    I digress, though. It would inevitably be lopsided somehow, because you’ve centered the numbering system around six months off of the New Years points.

  • That could work. Calculating across eras would still end up sort of funny (the putative nativity would be a year closer to 233BC than 233AD, for example), but unless you’re an archeologist that doesn’t come up that often.

    I had another conversation about this not that long ago, and it really does boil down to treating intervals as numbers. Unix epoch doesn’t officially extend to pre-1970 years, but it’s defined as “the number of seconds that have elapsed [past perfect] since” for that reason, and does have a second 0. It fair to guess Bede himself didn’t properly distinguish between the two, because that leads directly to an argument 0 is a number, which AFAIK doesn’t appear in European mathematics until much later.