Skip to content

Instantly share code, notes, and snippets.

View evanrelf's full-sized avatar

Evan Relf evanrelf

View GitHub Profile
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedLabels #-}
module X where
import Data.Functor.Identity (Identity (..))
import Data.Kind (Type)
import GHC.OverloadedLabels (IsLabel (..))
-- https://www.youtube.com/watch?v=dDtZLm7HIJs
{-# LANGUAGE BlockArguments #-}
module Main (main) where
import Control.Applicative
import Control.Monad (when)
import Data.Char
import Data.Foldable (for_)
#!/usr/bin/env runghc
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NegativeLiterals #-}
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
const A: usize = 2;
const B: usize = 3;
#[allow(clippy::assertions_on_constants)]
const _: () = {
assert!(2 <= A && A <= (B + 1) / 2, "Not a valid (a,b)-tree");
assert!(A == (B / 2) + (B % 2), "Not a valid B-tree");
};
module Main (main) where
import Control.Monad (when)
import Data.Proxy (Proxy (..))
import Data.String (IsString (..))
import Data.Void (Void)
import Type.Reflection
typeName
:: forall a s proxy
module Repeatedly where
import Data.Foldable (foldl', foldlM)
repeatedly :: (Foldable t) => (a -> b -> b) -> (t a -> b -> b)
repeatedly = flip . foldl' . flip
repeatedlyM :: (Foldable t, Monad m) => (a -> b -> m b) -> (t a -> b -> m b)
repeatedlyM = flip . foldlM . flip
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
import Data.Bits (toIntegralSized)
import Data.Function ((&))
import Data.Kind (Type)
import Data.Monoid (Sum (..))
import Data.Proxy (Proxy (..))
import Data.Sequence (Seq (..))
import Data.Sequence qualified as Seq
<script type="module" async>
// TODO: Fix error using `@codemirror/lang-markdown`:
// ```
// Uncaught TypeError: Cannot read properties of undefined (reading 'deserialize')
// at h (index.js:1585:48)
// at new l (index.js:1600:29)
// at l.deserialize (index.js:1841:16)
// at index.js:252:25
// ```
use std::fmt::{self, Display};
// TODO: Use tuples instead of arrays for heterogeneous lists
// TODO: Escaping
#[derive(Debug, PartialEq)]
pub enum Html {
Node(Node),
Text(String),
}
#!/usr/bin/env nix-shell
#!nix-shell -i ghcid -p ghcid "ghc.withPackages (p: with p; [ linear-base ])"
-- Rough, imperfect re-implementation of this article on using Swift's
-- "typestate" pattern. Haskell fails to replicate some aspects, and exceeds
-- Swift's capabilities in other areas.
--
-- https://swiftology.io/articles/typestate/
{-# LANGUAGE DataKinds #-}