Skip to content

Instantly share code, notes, and snippets.

filtering ::
Applicative f =>
(a -> f Bool)
-> List a
-> f (List a)
filtering p =
flip foldRight (pure Nil) $ \a fas ->
(\b as -> bool as (a :. as) b) <$> p a <*> fas
@bradparker
bradparker / Main.hs
Created March 2, 2021 23:45
Applicative record building from maps
module Main where
import Data.Foldable (traverse_)
import Data.Functor.Compose (Compose (Compose, getCompose))
import Data.Map (Map)
import qualified Data.Map as Map
data Person = Person
{ id :: Int,
name :: String,
@bradparker
bradparker / Primes.hs
Last active December 16, 2020 22:31
Prime sieve
{-# OPTIONS_GHC -Wall #-}
module Main where
import Control.Monad ((<=<))
import Data.Maybe (listToMaybe)
import Numeric.Natural (Natural)
import System.Environment (getArgs)
import Text.Read (readMaybe)
@bradparker
bradparker / .gitignore
Last active December 14, 2020 03:26
Advent of Code 2020
inputs
@bradparker
bradparker / Life.hs
Last active August 9, 2020 10:10
Life
{-# OPTIONS_GHC -Wall #-}
module Life where
import Data.Foldable (for_)
import Control.Comonad.Store (Comonad (..), Store, peek, peeks, store)
import Data.Array ((!), Array, array, bounds)
import Data.Bool (bool)
import Data.List (transpose)
@bradparker
bradparker / Main.hs
Last active February 10, 2021 05:48
I should put this somewhere
module Main where
import Control.Applicative ((<|>))
import Data.Time (TimeZone, ZonedTime, utc, utcToZonedTime, zonedTimeToUTC)
import Data.Time.Format.ISO8601 (iso8601ParseM)
import System.Environment (getArgs)
inTimeZone :: TimeZone -> ZonedTime -> ZonedTime
inTimeZone timezone = utcToZonedTime timezone . zonedTimeToUTC
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall #-}
module IntervalSets where
import Control.Arrow ((&&&))
import Control.Monad (filterM)
import Control.Monad.State (evalState, get, modify)
import Control.Monad.Trans.State (StateT (StateT), evalStateT)
@bradparker
bradparker / styled.rb
Last active June 7, 2020 01:21
Sketch of ViewComponent::Styled API
module ViewComponent
module Styled
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def styled(static = [], &block)
@static_styles = static
@dynamic_styles = block
@bradparker
bradparker / index.html
Last active March 31, 2020 11:47
WebCrypto based SRP
<!DOCTYPE html>
<html>
<head>
<title>SRP</title>
<meta charset="utf8" />
</head>
<body>
<script type="module">
import { modPow } from "https://unpkg.com/bigint-mod-arith@1.3.1/src/main.js";
@bradparker
bradparker / SKI.hs
Last active February 20, 2020 04:55
{-# LANGUAGE RankNTypes #-}
-- Prelude> :set -XTypeApplications
-- Prelude> :t id
-- id :: a -> a
-- Prelude> :t const
-- const :: a -> b -> a
-- Prelude> :t (<*>) @((->) _)
-- (<*>) @((->) _) :: (w -> a -> b) -> (w -> a) -> w -> b