Sign in

buster

@axionbuster.com
108 followers 114 following 92 posts

constant, yet volatile

PostsRepliesMedia
buster @axionbuster.com · 27/12/2024
i really like this example from heftia
prog :: IO ()
prog = runEff . runLog . runSpan $ do
    span "example program" do
        log "foo"

        span "greeting" do
            log "hello"
            log "world"

        log "bar"

>>> prog
[Start span 'example program']
[LOG] foo
[Start span 'greeting']
[LOG] hello
[LOG] world
[End span 'greeting']
[LOG] bar
[End span 'example program']
030
buster @axionbuster.com · 27/12/2024
TIL a purely functional double-ended queue with worst-case constant time access to either end is possible and that listing monads explicitly in such a data structure can improve the time complexity of certain operations (such as list concatenation) by changing assoc. of (>>=)
"Simple and efficient purely functional queues and deques," Chris Okasaki. Abstract. We present purely functional implementations of queues and double-ended queues (deques) requiring only O(1) time per operation in the worst case. Our algorithms are considerably simpler than previous designs with the same bounds. The inspiration for our approach is the incremental behavior of certain functions on lazy lists."Purely Functional, Real-Time Deques with Catenation," Haim Kaplan and Robert E. Tarjan. Abstract. We describe an efficient, purely functional implementation of eques with catenation. In addition to being an intriguing problem in its own right, finding a purely functional implementation of catenable deques is required to add certain sophisticated programming constructs to functional programming languages. Our solution has a worst-case running time of O(1) for each push, pop, inject, eject and catenation. The best previously known solution has an O(log* k) time bound for the kth deque operation. Our solution is not only faster but simpler. A key idea used in our result is an algorithmic technique related to the redundant digital representations used to avoid carry propagation in binary counting."Reflection without Remorse: Revealing a hidden sequence to speed up monadic reflection," Atze van der Plocg and Oleg Kiselyov. Abstract. A series of list appends or monad binds for many monads performs algorithmically worse when left-associated. Continuation-passing style (CPS) is well-known to cure this severe dependence of performance on the association pattern. The advantage of CPS dwindles or disappears if we have to examine or modify the intermediate result of that series of appends or binds, before continuing the series. Such examination is frequently needed, for example, to control search in non-determinism monads. We present an alternative approach that is just as general as CPS but more robust: it makes series of binds and other such operations efficient regardless of the association pattern -- and also provides efficient access to intermediate results. The key is to represent such a conceptual sequence as an efficient sequence data structure. Efficient sequence data structures from the literature are homogeneous and cannot be applied as they are in a type-safe way to series of monadic binds. We generalize them to type aligned sequences and show how to construct their (assuredly order-preserving) implementations. We demonstrate that our solution solves previously undocumented, severe performance problems in iteratees, LogicT transformers, free monads and extensible effects.
130
buster @axionbuster.com · 21/12/2024
can anyone explain how this works?
-- | a mysterious module that apparently samples points on the face of a coid
module Face (facepoints, dbgcountfacepoints, dbgdesmos) where

import Control.Lens hiding (index)
import Data.Functor.Rep
import Data.Ix (range)
import Data.List (intercalate)
import Linear.V3
import Text.Printf

-- | retrieve the points on the faces of a cuboid
-- normal to a certain direction (sig: {-1, 0, 1}) from said cuboid
facepoints :: V3 Int -> V3 Int -> [V3 Int]
facepoints coid sig =
  let (!) = index
      -- p, q, r: dimensions
      -- ps: list of points to sample (?)
      -- h: permutation of a V3
      rule p q r ps h
        | sig ! p == 0 = []
        | otherwise =
            [ let a = if i >= coid ! r then coid ! r else i
                  b = if j >= coid ! q then coid ! q else j
                  c = if sig ! p < 0 then 0 else coid ! p
               in h do V3 a b c
            | (i, j) <- ps
            ]
      -- this thing is a total mystery to me
      st i -- compute starting / ending points for the face (?) in dimension i
        | sig ! i < 0 = (1, 0)
        | sig ! i > 0 = (0, 1)
        | otherwise = (0, 0)
      h0 (V3 a b c) = V3 c b a
      h1 (V3 a b c) = V3 b c a
      h2 (V3 a b c) = V3 b a c
      p0 =
        let (sj, ej) = st ey
            (si, ei) = st ez
         in range ((si, sj), (coid ! ez - ei, coid ! ey - ej))
      p1 =
        let (sj, ej) = st ez
         in range ((sj, 0), (coid ! ez - ej, coid ! ex))
      p2 = range ((0, 0), (coid ! ey, coid ! ex))
   in concat
        [ rule ex ey ez p0 h0,
          rule ey ex ez p1 h1,
          rule ez ex ey p2 h2
        ]

-- | print a list of vectors in a format that can be copy-pasted into Desmos
dbgdesmos :: (Show a) => [V3 a] -> String
dbgdesmos vs = "[" ++ intercalate "," (f <$> vs) ++ "]"
  where
    f (V3 x y z) = printf "(%s,%s,%s)" (show x) (show y) (show z)

-- | predict the number of points sampled by 'facepoints'
dbgcountfacepoints :: V3 Int -> V3 Int -> Int
dbgcountfacepoints ((+ pu…
000
buster @axionbuster.com · 21/12/2024
undefined behavior can really do anything
Does Infinity - Infinity = an Electron?
000
buster @axionbuster.com · 20/12/2024
maybe i should have called 'loop' 'this' for funsies
dda start end = do
  let fi = fromIntegral :: i -> Double
      difference = liftM2 (-) end start
      steps = maximum $ abs <$> difference
      step = ((/ fi steps) . fi) <$> difference
  v <- newSTRef `traverse` fmap fi start
  (succ steps,) <$> fix \this -> do
    v' <- traverse readSTRef v
    forM_ (mzip v step) \(r, s) -> modifySTRef r (+ s)
    (fmap round v' :) <$> this -- lazy list
100
buster @axionbuster.com · 20/12/2024
DDA line drawing algorithm, dimension-independent, lazy, infinite original algorithm is from Wikipedia (for 2D, in C) image: magnified image output, (0, 0) to (10, 5)
-- | the DDA line drawing algorithm
-- (dimension-independent, lazy, infinite)
--
-- you can generate an infinite ray by
-- ignoring the number of steps
--
-- algorithm is due to Wikipedia
dda ::
  forall f i s.
  (Traversable f, MonadZip f, Integral i) =>
  -- | The starting point
  f i ->
  -- | The ending point
  f i ->
  -- | The number of steps (points) to get to the end
  -- and the points
  ST s (i, [f i])
dda start end = do
  let fi = fromIntegral :: i -> Double
      difference = liftM2 (-) end start
      steps = maximum $ abs <$> difference
      step = ((/ fi steps) . fi) <$> difference
  v <- newSTRef `traverse` fmap fi start
  (succ steps,) <$> fix \loop -> do
    v' <- traverse readSTRef v
    forM_ (mzip v step) \(r, s) -> modifySTRef r (+ s)
    (fmap round v' :) <$> loop -- lazy listmagnified image output, (0, 0) to (10, 5)
100
buster @axionbuster.com · 20/12/2024
the usefulness of MultiWayIf in Haskell programming cannot be overstated (but you could hack it using case () of _ | condition1 -> expression1; _ | condition2 -> expression2; ...)
if
  | all id needs -> do
      enqueue $ newpoint2 ex ey
      unless smooth do
        enqueue $ newpoint2 ey ez
        enqueue $ newpoint2 ex ez
        enqueue $ newpoint1 ex
        enqueue $ newpoint1 ey
        enqueue $ newpoint1 ez
  | needs ^. el ex && needs ^. el ey -> do
      enqueue $ newpoint1 ex
      unless smooth do
        enqueue $ newpoint1 ey
  | needs ^. el ex && needs ^. el ez -> do
      enqueue $ newpoint1 ex
      unless smooth do
        enqueue $ newpoint1 ez
  | needs ^. el ey && needs ^. el ez -> do
      enqueue $ newpoint1 ey
      unless smooth do
        enqueue $ newpoint1 ez
  | otherwise -> pure ()
031
buster @axionbuster.com · 20/12/2024
“is this object oriented mathematics?”
YouTube. A Sensible Introduction to Category Theory by Oliver Lugg.

Comment. Is this object oriented mathematics?
000
buster @axionbuster.com · 20/12/2024
there's a whole community on the internet accumulating knowledge about teaching, metathinking and problem solving amazing
100
buster @axionbuster.com · 20/12/2024
digging this aesthetic
1945 SIGSALY 1946
SPEECH ENCIPHERMENT SYSTEM
A lectern surrounded by walls made of hardware
010
buster @axionbuster.com · 19/12/2024
how to fix error
000
buster @axionbuster.com · 19/12/2024
writing imperative code in haskell was a mistake
extrapoints :: STRef s (Seq IP) <- new Seq.empty -- right-to-left, FIFO
out :: STRef s [IP] <- new []
callCC \break_ -> do
  let break = break_ ()
  fix \continue -> do
    let tell = write out
    read extrapoints >>= \case
      a :<| points -> do
        tell [a]
        if sameblock a end
          then break
          else continue
      _ -> pure ()
    -- todo...
    break
351
buster @axionbuster.com · 17/12/2024
Variadic Composition (uses the Text.Printf trick) (language: GHC2021, no other extensions)
010
buster @axionbuster.com · 17/12/2024
can you find a solution to this problem? (or decide that there is not)
000
buster @axionbuster.com · 12/12/2024
fun fact i learned. a box-box collision problem can be reduced to a ray-box collision problem
100
buster @axionbuster.com · 12/12/2024
ormolu
000
buster @axionbuster.com · 01/12/2024
I just completed "Historian Hysteria" - Day 1 - Advent of Code 2024 #AdventOfCode adventofcode.com/2024/day/1
220
buster @axionbuster.com · 01/12/2024
#adventofcode2024 #Haskell is the new #Python
210
buster @axionbuster.com · 01/12/2024
Some brand names on Amazon look like randomly generated and yet manage to deliver good stuff
WSAKOUE (R) WORKOUT EXERCISE BAND
200
buster @axionbuster.com · 29/11/2024
This week is refactoring week. I’m moving a proof of concept demo into an actual framework. This is my movement code. I explored so many options that now I doubt I can make the code simpler. Try reading it.
100
buster @axionbuster.com · 29/11/2024
Investor Marc Andreessen went on Joe Rogan Experience and said the CFPB was “debanking” people who were on the right. His company LendUp was implicated committed a crime and the CFPB stopped it.
000
buster @axionbuster.com · 29/11/2024
On X/Twitter they’re seriously trying to cancel CFPB, wow. The DOGE wants it gone.
100
buster @axionbuster.com · 26/11/2024
I just got back access to the internet, and I fixed the sound. I was multiplying the source coordinates by an extra factor of 8. That's fixed.
Subtitle says "Player hurts"
010
buster @axionbuster.com · 20/11/2024
I've gotten the most basic aspect of PvP working: damage animation. But I can't get the sound to play for some reason. A clever thing Minecraft does is the client calculates the hits, reducing the burden on the server. The server only checks if they're valid.
000
buster @axionbuster.com · 19/11/2024
Cool thing I'm working on. This is a Minecraft server being developed from scratch. I'm able to synchronize player movement. But the server doesn't understand blocks yet, so block information isn't being sent to other players.
010