This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE QualifiedDo #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE OverloadedLabels #-} | |
module X where | |
import Data.Functor.Identity (Identity (..)) | |
import Data.Kind (Type) | |
import GHC.OverloadedLabels (IsLabel (..)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runghc | |
{-# LANGUAGE BlockArguments #-} | |
{-# LANGUAGE DerivingStrategies #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE NegativeLiterals #-} | |
{-# OPTIONS_GHC -Wall #-} | |
{-# OPTIONS_GHC -Wno-unused-top-binds #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 | |
// ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 #-} |
NewerOlder