Skip to content

Instantly share code, notes, and snippets.

View rampion's full-sized avatar

Noah Luck Easterly rampion

  • Mercury Technologies
View GitHub Profile
@rampion
rampion / Description.md
Last active June 27, 2025 09:58
Computing fixed-width monoidal sliding windows with chunked partial sums

In Brent Yorgey's post about monoidal sliding windows he used a queue to represent the fixed-size sliding window.

Due to the fixed size, however, the append stack was reversed to become a new pop stack for the queue at very regular intervals. Intervals of exactly the width of the fixed window.

In effect then, what the queue was computing was prefix and suffix monoidal sums, not over the entire list, but over discrete chunks of the list the one smaller than the size of the fixed window.

For example, say the window size is 5, and our input list is [a0, a1, a2, ..., a21].

@rampion
rampion / Zigzag.hs
Created June 12, 2025 19:43
Zigzag conversion
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wall -Wextra -Werror -Wno-name-shadowing -Wno-incomplete-uni-patterns #-}
-- An implementation of the zigzag conversion (https://mmhaskell.com/blog/2025/6/9/spatial-reasoning-with-zigzag-patterns) that
-- rearranges the string directly, rather by computing indexes
module Zigzag where
import Data.List
import System.Exit (die)

This is a sentence on a single line with a trailing space. Here is a sentence on the next line.

This is a sentence on a single line without a trailing space. Here is a sentence on the next line.

This is a sentence on a single line with two a trailing spaces.
Here is a sentence on the next line.

{-# OPTIONS_GHC -Wall -Wextra -Werror #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
module Partition where
import Data.Functor.Identity
import Data.Kind
{-# OPTIONS_GHC -Wall -Wextra -Werror #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeFamilies #-}
module Partition where
import Data.Kind
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wall -Wextra -Werror #-}
-- https://exercism.org/tracks/haskell/exercises/crypto-square
module CryptoSquare where
import Data.Char (isLower, toLower)
@rampion
rampion / Magnitude.hs
Created May 13, 2024 14:03
Lazy calculation of list length; update of https://gist.github.com/rampion/6337593
{-# OPTIONS_GHC -Wall -Wextra -Werror #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
-- |
-- Types for lazy length computation and comparison
--
-- >>> length (replicate 5 'a')
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
@rampion
rampion / ZipWith.hs
Last active July 8, 2021 03:52
Two implementations of a variadic `zipWith` function, based on inferring the type using either the argument or the return type
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module ZipWith where
import Control.Applicative (ZipList (..))
import Prelude hiding (zipWith)
@rampion
rampion / Lib.hs
Last active May 24, 2021 00:55
ShortestLongest
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall -Wextra -Werror -Wno-name-shadowing -Wno-unused-top-binds #-}
module Lib
( shortestLongest,
)
where